PDA

View Full Version : Dropdown to diplay specific info


kona72
12-21-2006, 06:12 PM
Hi All,

I am using a drop down menu to display the different retailers in particular states. I have been through the VTM a couple of times and searched the forum but I cannot figure out what i have done wrong....

Here is the page code....


<?php require_once('Connections/companion.php');

$retail = $_POST['retail'];


if ($retail) {
///////////////////////////////////////////////////
$query = sprintf("SELECT * retailers where state='$retail'");
$result = @mysql_query($query);
$row_rsRetail = mysql_fetch_array($rsRetail);
////////////////////////////////////////////////
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<body>
<p class="td_borderBgTXT">Please Support Our Retailers</p>

<p><span class="large_text">Please Select a State to view</span></p>
<form id="form1" name="form1" method="post" action="retailers_all.php" >
<select name="retail" id="retail" onChange="document.forms[0].submit()">
<option value="value">Select a State</option>
<option value="WI">Wisconsin</option>
<option value="TX">Texas</option>
<option value="MN">Minnesota</option>
<option value="MI">Michigan</option>
<option value="IN">Indiana</option>
<option value="IL">Illinois</option>
<option value="FL">Florida</option>
</select>
</form>
<p>&nbsp;</p>
<p><span class="main_text"></span>

<?php
//////////////////this diplays the retail location according to state picked///////////////
do {
echo $row_rsRetail['retailer']. "<br>";
echo $row_rsRetail['address']. "<br>";
echo $row_rsRetail['city']. "<br>";
echo $row_rsRetail['state']. "<br>";
echo $row_rsRetail['phone']. "<br>";
}
while ($row_rsRetailers = mysql_fetch_assoc($rsRetail))
?>
</html>
<?php
mysql_free_result($rsRetail);
?>


I have the following fields in my table...
rec_number
retailer
address
city
state
phone
url

I am getting theses errors right now....

WARNING: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\CompanionNatural\retailers_all2.php on line 21

and

WARNING: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\CompanionNatural\retailers_all2.php on line 60

davidj
12-21-2006, 07:04 PM
add an @...

$row_rsRetail = @mysql_fetch_array($rsRetail);

kona72
12-27-2006, 07:54 PM
Hey David,

Tried that.... I stripped out all of the unnecessary code and now have this... Still nothing though....

Here is a link to the page as well...

http://www.companionnaturalpetfood.com/retailers_all2.php


<?php require_once('Connections/companion.php');

$retail = $_POST['retail'];


if ($retail) {
///////////////////////////////////////////////////
$query = sprintf("SELECT * retailers where state='$retail'");
$result = @mysql_query($query);
$row_rsRetail = @mysql_fetch_array($rsRetail);
////////////////////////////////////////////////
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<body>
<p class="td_borderBgTXT">Please Support Our Retailers</p>

<p><span class="large_text">Please Select a State to view</span></p>
<form id="form1" name="form1" method="post" action="retailers_all2.php" >
<select name="retail" id="retail" onChange="document.forms[0].submit()">
<option value="value">Select a State</option>
<option value="WI">Wisconsin</option>
<option value="TX">Texas</option>
<option value="MN">Minnesota</option>
<option value="MI">Michigan</option>
<option value="IN">Indiana</option>
<option value="IL">Illinois</option>
<option value="FL">Florida</option>
</select>
</form>
<p>&nbsp;</p>
<p><span class="main_text"></span>

<?php
//////////////////this diplays the retail location according to state picked///////////////
do {
echo $row_rsRetail['retailer']. "<br>";
echo $row_rsRetail['address']. "<br>";
echo $row_rsRetail['city']. "<br>";
echo $row_rsRetail['state']. "<br>";
echo $row_rsRetail['phone']. "<br>";
}
while ($row_rsRetailers = @mysql_fetch_assoc($rsRetail))
?>
</html>
<?php
mysql_free_result($rsRetail);
?>

davidj
12-27-2006, 08:14 PM
please post your database ddl so i can build your tables and test it at this side

kona72
12-27-2006, 08:22 PM
Sure... here is the sql with all the data as well...

obviously renamed to .txt....

davidj
12-27-2006, 08:56 PM
where you have...

SELECT * retailers where state='$retail'

you have missed the FROM clause in the SQL.

where you have...

@mysql_fetch_array($rsRetail);


this should be...

@mysql_fetch_array($result);


also you don really need to free the result at the end of the page as this is done anyway when the script terminates.
i suppose you could use it when using huge queries

kona72
12-27-2006, 09:51 PM
Hey David,

Did it work for you? It didn't for me.... I am not sure what i am doing wrong here....

davidj
12-27-2006, 09:58 PM
Try this

<?php require_once('Connections/companion.php');

$retail = $_POST['retail'];


if ($retail) {
///////////////////////////////////////////////////
$query = sprintf("SELECT * from retailers where state='$retail'");
$result = @mysql_query($query);
$row_rsRetail = @mysql_fetch_array($result);
////////////////////////////////////////////////
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<body>
<p class="td_borderBgTXT">Please Support Our Retailers</p>

<p><span class="large_text">Please Select a State to view</span></p>
<form id="form1" name="form1" method="post" action="retailers_all2.php" >
<select name="retail" id="retail" onChange="document.forms[0].submit()">
<option value="value">Select a State</option>
<option value="WI">Wisconsin</option>
<option value="TX">Texas</option>
<option value="MN">Minnesota</option>
<option value="MI">Michigan</option>
<option value="IN">Indiana</option>
<option value="IL">Illinois</option>
<option value="FL">Florida</option>
</select>
</form>
<p>&nbsp;</p>
<p><span class="main_text"></span>

<?php
//////////////////this diplays the retail location according to state picked///////////////
do {
echo $row_rsRetail['retailer']. "<br>";
echo $row_rsRetail['address']. "<br>";
echo $row_rsRetail['city']. "<br>";
echo $row_rsRetail['state']. "<br>";
echo $row_rsRetail['phone']. "<br>";
}
while ($row = @mysql_fetch_assoc($rsRetail))
?>
</html>


in the sql you sent me you only have values for WI and IL