Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

drop down and mysql

Posted 08 Nov 2006 04:40:11
1
has voted
08 Nov 2006 04:40:11 bill triplett posted:
Need a simple script that uses a drop down menu to search a mysql db and return all matching records. The script I am using only returns the first record match.

Replies

Replied 08 Nov 2006 10:50:57
08 Nov 2006 10:50:57 LorD ExoskeletoN replied:
can you post your codes so that we can work on it...
Replied 08 Nov 2006 18:14:48
08 Nov 2006 18:14:48 bill triplett replied:
<?
// Connect database
mysql_connect("localhost","rdub","bub";
mysql_select_db("members";

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""{
$select=$_GET['select'];
}
?>
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form ID="form1" Categor Listing"form1" method="get" action="<? echo $PHP_SELF; ?> ">
Selections :
<select name="select">
<option value="">--- Select ---</option>
<?
// Get records from database (table "member_list".
$list=mysql_query("select * from member_list order by id asc";

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['ID']; ?>"
<? if($row_list['ID']==$select){ echo "selected"; } ?>>
<? echo $row_list['Category_Listing']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<hr>
<p>
<?
// If you have selected from list box.
if(isset($select)&&$select!=""{

// Get records from database (table "member_list".
$result=mysql_query("select * from member_list where ID='$select'";
while($row=mysql_fetch_assoc($result)) {



?>



Information about <strong><? echo $row['Customer']; ?></strong> company...</p>

<?
// End While statement
}
// End if statement.
}


// Close database connection.
mysql_close();
?>
</p>
</body>
</html>
Replied 09 Nov 2006 02:50:57
09 Nov 2006 02:50:57 LorD ExoskeletoN replied:
hey bill try this one:

You must get first the $select before testing it...

$select=$_GET['select'];

if (isset($select) && $select!="" {

codes here.....................

}


// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.

You test the $select first before getting it from the URL, i think that's the error:

if (isset($select) && $select!="" {

$select=$_GET['select'];

codes here.....................

}

Hope this helps...good luck!!
Replied 11 Nov 2006 20:02:21
11 Nov 2006 20:02:21 bill triplett replied:
Thanks for your help. The display issue seems to be resolved. Now, when the page is displayed the last category in the Category_Listing column shows in the selection box instead of --select--.

This is the current/changed code

<?
// Connect database
mysql_connect("localhost","rdub","bub";
mysql_select_db("members";

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""{
$select=$_GET['select'];
}
?>
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form ID="form1" Category Listing"form1" method="get" action="<? echo $PHP_SELF; ?> ">
Selections :
<select name="select">
<option value="">--- Select ---</option>
<?
// Get records from database (table "member_list".
$list=mysql_query("select distinct Category_Listing from member_list order by id asc";

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['Category_Listing']; ?>"
<? if($row_list['ID']==$select){ echo "selected"; } ?>>
<? echo $row_list['Category_Listing']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<hr>
<p>
<?
// If you have selected from list box.
if(isset($select)&&$select!=""{

// Get records from database (table "member_list".
$result=mysql_query("select * from member_list where Category_Listing='$select'";
while($row=mysql_fetch_assoc($result)) {



?>



Information about <strong><? echo $row['Customer']; ?></strong> company...</p>

<?
// End While statement
}
// End if statement.
}


// Close database connection.
mysql_close();
?>
</p>
</body>
</html>
Replied 17 Nov 2006 03:04:08
17 Nov 2006 03:04:08 LorD ExoskeletoN replied:
That's great....never give up ok..dont let your programs make you problematic...let it instead ok...

<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle><img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle> More power bill

<div align=right>
afraid NOT to FAIL for you learn NOTHING

www.nasbikesphilippines.bravehost.com
<img src="www.motorcyclephilippines.com/forums/signaturepics/sigpic14460_2.gif" border=0></div id=right>

Reply to this topic