This topic is locked

Left 'Search by...' menu

1/15/2008 4:17:08 AM
PHPRunner General questions
M
mmponline author

I need to add a "search by category" and "search by location" menu on the left of my list page similar to the cars template on my adventures table's list page.
I've added a {$row00Advent_Search_value} in the page and copied the event in "listonload " from the cars list page listonload to the adventures table's list events listonload and made all the field and table changes (I think?).

When I upload the files, I get the following error: Undefined variable: Category
Here is the code:

global $strSQL,$conn, $smarty;
//search by brand

$message="<b>Search by Category<br>";

$str = "select count(Category) as numbers, Category from adventures group by Category";

$rs = db_query($str,$conn);

while ($data = db_fetch_array($rs))

{

$make = str_replace(" ","+",$data["Category"]);

$message = $message ."<a href=\"adventures_list.php?a=search&value=1&SearchFor=".$Category."&SearchOption=Contains&SearchField=Category\">".$data["Category"]." (".$data["numbers"].")</a>";

$message = $message ."<br>";

}
//show all

$message = $message ."<br><a href=\"adventures_list.php?a=showall&value=1&SearchFor=&SearchOption=&SearchField=\">Show All</a><br><br>";
//search by category

$message = $message ."Search by Location<br>";

$str2 = "select count(Location) as numbers, Location from adv ntures where Location!='' and Location is not NULL group by Location";

$rs2 = db_query($str2,$conn);

while ($data2 = db_fetch_array($rs2))

{

$Location = str_replace(" ","+",$data2["Location"]);

$message = $message ."<a href=\"adventures_list.php?a=search&value=1&SearchFor=".$Location."&SearchOption=Contains&SearchField=Location\">".$data2["Location"]." (".$data2["numbers"].")</a>";

$message = $message ."<br>";

}

$smarty->assign("row00Advent_Search_value",$message);


What am I doing wrong?
Wishlist! - It would be great to somehow have a feature where this can be a standard event or feature to put in menus like this in a project..
Thanks for your help.

J
Jane 1/15/2008

Stephan,
you should use code in the Cars template as a sample and customize this code using your data.

For example replace $Category with $data["Category"] in your code:

...

$message = $message ."<a href=\"adventures_list.php?a=search&value=1&SearchFor=".$data["Category"]."&SearchOption=Contains&SearchField=Category\">".$data["Category"]." (".$data["numbers"].")</a>";

...

M
mmponline author 1/15/2008

Jane
I've done just that:

Cars code:

...

$message = $message ."<a href=\"cars_list.php?a=search&value=1&SearchFor=".$make."&SearchOption=Contains&SearchField=Make\">".$data["Make"]." (".$data["numbers"].")</a>";

...

My code:

...

$message = $message ."<a href=\"adventures_list.php?a=search&value=1&SearchFor=".$Category."&SearchOption=Contains&SearchField=Category\">".$data["Category"]." (".$data["numbers"].")</a>";

...


If I replace it with the code you supplied - (different from the cars code):

...

$message = $message ."<a href=\"adventures_list.php?a=search&value=1&SearchFor=".$data["Category"]."&SearchOption=Contains&SearchField=Category\">".$data["Category"]." (".$data["numbers"].")</a>";

...


I get the following error:

Table 'advent_db2.adv' doesn't exist

M
mmponline author 1/17/2008

I managed using the event code from the realty template. Somehow this worked better for me. Have not tried to add a second menu, but hopefully I will be able to get it working.
And the Show all one.
Thanks
Stephan