I am having trouble putting together a script that lists various business contact information.
Basically, the a user can either enter a business name, or choose from a set or categories, then click on the submit button, which then begins the search for results stored in a mysql database. This part works fine, as in a user can enter a name or choose a category, then click the button to see a table listing matching results. These results are paged in sets of 6.
Here is the code for the layout of the form:
$pageContent = '
<div class="content">
<h1>Browse Listings</h1>
<div class="searchBox">
<form method="post" action="'.$_SERVER['PHP_SELF'].'" name="search">
Enter a Business Name: <input name="bizName" type="text" size="25" placeholder="Search..." />
or Select a Category: <select name="bizCategory">
<option>Choose</option>
<option>Accomodation</option>
<option>Retail</option>
</select>
<button type="submit" name="searching" class="search" value="Search">Search</button>
<!-- end .searchBox --></div>
<br />
';
Here is the code that deals with the instance of a user clicking on Search when they have entered a name:
if ((isset($_POST['searching']) && $_POST['searching'] == "Search") || isset($_SESSION['bizFind']))
{
if ((isset($_POST['bizName']) && $_POST['bizName'] == "") && $_POST['bizCategory'] == "Choose")
{
$pageContent .= '
<p>You forgot to enter a business name, or select a search category.</p>
';
} else {
...
if (((isset($_POST['bizName']) && $_POST['bizName'] !== "") && $_POST['bizCategory'] == "Choose") || (isset($_SESSION['bizFind']) && !in_array($_SESSION['bizFind'], array("", "Accomodation", "Retail"))))
{
if ((isset($_SESSION['bizFind']) && !in_array($_SESSION['bizFind'], array("", "Accomodation", "Retail"))) && !isset($bizFind))
{
$bizFind = $_SESSION['bizFind'];
}
else
{
$bizFind = $_POST['bizName'];
}
With the emphasis on this line, being the actual instance:
if (((isset($_POST['bizName']) && $_POST['bizName'] !== "") && $_POST['bizCategory'] == "Choose") || (isset($_SESSION['bizFind']) && !in_array($_SESSION['bizFind'], array("", "Accomodation", "Retail"))))
Now when a user navigates away from a page, and navigates back, the search value is held and the results are displayed.
But I cannot for some reason grasp the statement behind a user clicking Search, after selecting a category.
I have tried this:
if ((isset($_POST['bizCategory']) && $_POST['bizCategory'] !== "Choose") || (isset($_SESSION['bizFind']) && ($_SESSION['bizFind'] == "Accomodation" || $_SESSION['bizFind'] == "Retail"))
{
if ((isset($_SESSION['bizFind']) && ($_SESSION['bizFind'] == "Accomodation" || $_SESSION['bizFind'] == "Retail")) && !isset($bizFind))
{
$bizFind = $_SESSION['bizFind'];
}
else
{
$bizFind = $_POST['bizCategory'];
}
Which will trigger if a category is selected and a user hits Search, but will not trigger if the session variable has been set and a user navigates back to the listing area.
This causes a problem too with the paging, when a search category has been selected.
If the business name is used, the paging works fine, but when a category is selected, and a user tries to navigate to the next page of results, no data is returned as the variable $bizFind (search string) has not been set, or holds no value.
If anyone has any input, or suggestions for me, with this... It would be greatly appreciated.
But the question is what am i doing wrong with the second instance, that the script is not being trigged by the existance of the session variable (search string) alone.
Thank You!!