This topic is locked

Search by city.

7/19/2008 7:56:49 AM
PHPRunner General questions
N
Nelson author

Hi,

I am trying to undrestand a last function in the "RealEstate" project, before I start building a site.

The function which would be very useful for users is the search by City function at the main list page in the "RealEstate" project,I'v outlined the function which I mean below in the pic;


What I did so far is this;

I created a single table (Table21).

I created a ID field and City field in the Table21.
At the list page in the Visual Editor(html mode) I put this code in the City's field

  • <A href="{$row.href}">{$row.1City_value}</A>
    And at the Events (Listpage--->ListonLoad) I gave it a custom code as below;

    //** Custom code ****

    // put your custom code here

    global $conn,$smarty;

    $rowsearch=array();

    $rstt = db_query("SELECT Table21.City, Count(Table21.City) AS CountOfCity FROM Table21 GROUP BY Table21.City", $conn);

    $ind=0;

    while($data=db_fetch_array($rstt))

    {

    $rows=array();

    $CityName = str_Replace(" ","+",$data["City"]);

    $rows["href"]="Table21_list.php?a=search&value=1&SearchFor=".$CityName."&SearchOption=Contains&SearchField=City";

    $rows["1City_value"]=$data["City"]." (".$data["CountOfCity"].")";

    $rowsearch[$ind]=$rows;

    $ind=$ind+1;

    }

    $smarty->assign("rowsearch", $rowsearch);
    ***
    And I've got this error(pic below);


How should I solve this issue..I'll be thankful for your help!

Nelson

N
Nelson author 7/21/2008

I guess error comes from this part of the code:'CountOfCity FROM Table21'
I don't know how to create this one!

J
Jane 7/21/2008

Nelson,
your code looks good.

Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

M
mmponline 7/21/2008

Here is the code I use and it works perfectly:

global $conn,$smarty;

$rowsearch=array();

$rstt = db_query("SELECT TropicProducts.Materials, Count(TropicProducts.Materials) AS CountOfMaterials FROM TropicProducts GROUP BY TropicProducts.Materials", $conn);

$ind=0;

while($data=db_fetch_array($rstt))

{

$rows=array();

$MaterialsName = str_Replace(" ","+",$data["Materials"]);

$rows["href"]="TropicProducts_list.php?a=search&value=1&SearchFor=".$MaterialsName."&SearchOption=Contains&SearchField=Materials";

$rows["1Materials_value"]=$data["Materials"]." (".$data["CountOfMaterials"].")<br>";

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

echo $rowsearch;

}


Replace TropicProducts with your tablemane

Replace Materials with your fieldname.
to add where statements: Put Eg. WHERE Active='Yes' before GROUP BY
To show menu itms next to each other, remove
in 3th last line

I normally add a manual link afterwards for Show All (hyperlinked to the table's list page)

N
Nelson author 7/21/2008

Here is the code I use and it works perfectly:


global $conn,$smarty;

$rowsearch=array();

$rstt = db_query("SELECT TropicProducts.Materials, Count(TropicProducts.Materials) AS CountOfMaterials FROM TropicProducts GROUP BY TropicProducts.Materials", $conn);

$ind=0;

while($data=db_fetch_array($rstt))

{

$rows=array();

$MaterialsName = str_Replace(" ","+",$data["Materials"]);

$rows["href"]="TropicProducts_list.php?a=search&value=1&SearchFor=".$MaterialsName."&SearchOption=Contains&SearchField=Materials";

$rows["1Materials_value"]=$data["Materials"]." (".$data["CountOfMaterials"].")<br>";

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

echo $rowsearch;

}


Replace TropicProducts with your tablemane

Replace Materials with your fieldname.
to add where statements: Put Eg. WHERE Active='Yes' before GROUP BY
To show menu itms next to each other, remove
in 3th last line

I normally add a manual link afterwards for Show All (hyperlinked to the table's list page)


Thanks Stephan,

I still get the same error: Table 'newtin_net_1.LastTable' doesn't exist

I guess there is something wrong with the way I created my table..I send the test project to Jane...I'll wait for the answer.
Thanks so much for the help Stephan!..have a great day!