This topic is locked

More than one item on left menu.

1/21/2008 5:01:00 AM
PHPRunner General questions
M
mmponline author

I have created (using Real estate template as example) the following quick left menu. Works fine.

//********** Custom code ************

// search by category

global $conn,$smarty;

$rowsearch=array();

$rstt = db_query("SELECT adventures.Category, Count(adventures.Category) AS CountOfCategory FROM adventures GROUP BY adventures.Category", $conn);

$ind=0;

while($data=db_fetch_array($rstt))

{

$rows=array();

$CategoryName = str_Replace(" ","+",$data["Category"]);

$rows["href"]="adventures_list.php?a=search&value=1&SearchFor=".$CategoryName."&SearchOption=Contains&SearchField=Category";

$rows["1Category_value"]=$data["Category"]." (".$data["CountOfCategory"].")";

$rowsearch[$ind]=$rows;

$ind=$ind+1;

}
$smarty->assign("rowsearch", $rowsearch);


I now need to add a second one giving me results of say City, or Province. How would I customise (add) to the above code to achieve this?

Alexey admin 1/21/2008

Stephan,
open your page in Visual Editor and right-click to the place where you want to insert the quick menu.

Select Insert PHP Code snippet.

Copy and Paste the code from your post there.

Replace all Categorywith Cityin the code.

Replace the last $smarty->assign...line with the following:

echo $rowsearch;

M
mmponline author 1/21/2008

Alexey
I've copied it into the custom code: (Location replaced Category)

//********** Custom code ************

// search by location

global $conn,$smarty;

$rowsearch=array();

$rstt = db_query("SELECT adventures.Location, Count(adventures.Location) AS CountOfLocation FROM adventures GROUP BY adventures.Location", $conn);

$ind=0;

while($data=db_fetch_array($rstt))

{

$rows=array();

$LocationName = str_Replace(" ","+",$data["Location"]);

$rows["href"]="adventures_list.php?a=search&value=1&SearchFor=".$LocationName."&SearchOption=Contains&SearchField=Location";

$rows["1Location_value"]=$data["Location"]." (".$data["CountOfLocation"].")";

$rowsearch[$ind]=$rows;

$ind=$ind+1;

}
echo $rowsearch;


The result is the following: Array

Nothing else, no error messages.

???

M
mmponline author 1/22/2008

Any help, please!

J
Jane 1/22/2008

Stephan,
try to use this code:

...

$rows["href"]="adventures_list.php?a=search&value=1&SearchFor=".$LocationName."&SearchOption=Contains&SearchField=Location";

$rows["1Location_value"]=$data["Location"]." (".$data["CountOfLocation"].")";

$rowsearch="<a href=\"".$rows["href"]."\">".$rows["1Location_value"]."</a>";

echo $rowsearch;

}

M
mmponline author 1/22/2008

Now: Error description Undefined variable: LocationName
Still stuck!

J
Jane 1/23/2008

Stephan,
it seems that you've removed some code in your event.

Check your code carefully.

M
mmponline author 1/23/2008

I used it as you supplied:

$rows["href"]="adventures_list.php?a=search&value=1&SearchFor=".$LocationName."&SearchOption=Contains&SearchField=Location";

$rows["1Location_value"]=$data["Location"]." (".$data["CountOfLocation"].")";

$rowsearch="<a href=\"".$rows["href"]."\">".$rows["1Location_value"]."</a>";

echo $rowsearch;


and the following:

global $conn,$smarty;

$rowsearch=array();

$rstt = db_query("SELECT adventures.Location, Count(adventures.Location) AS CountOfLocation FROM adventures GROUP BY adventures.Location", $conn);

$ind=0;

while($data=db_fetch_array($rstt))

{

$rows["href"]="adventures_list.php?a=search&value=1&SearchFor=".$LocationName."&SearchOption=Contains&SearchField=Location";

$rows["1Location_value"]=$data["Location"]." (".$data["CountOfLocation"].")";

$rowsearch="<a href=\"".$rows["href"]."\">".$rows["1Location_value"]."</a>";

echo $rowsearch;

}


Same undefined variable error.

J
Jane 1/23/2008

Stephan,
you've remove two lines.

Here is the correct code:

global $conn,$smarty;

$rowsearch=array();

$rstt = db_query("SELECT adventures.Location, Count(adventures.Location) AS CountOfLocation FROM adventures GROUP BY adventures.Location", $conn);

$ind=0;

while($data=db_fetch_array($rstt))

{

$rows=array();

$LocationName = str_Replace(" ","+",$data["Location"]);

$rows["href"]="adventures_list.php?a=search&value=1&SearchFor=".$LocationName."&SearchOption=Contains&SearchField=Location";

$rows["1Location_value"]=$data["Location"]." (".$data["CountOfLocation"].")";

$rowsearch="<a href=\"".$rows["href"]."\">".$rows["1Location_value"]."</a>";

echo $rowsearch;

}

M
mmponline author 1/23/2008

Thank you! Works perfctly. Will surely save this code somewhere.