-
Drop Down Results
I have a sql qyery which i want to add the results to a drop down menu.
PHP Code:
<?php
$link = mysql_connect (localhost, user, pass);
mysql_select_db (db12816e);
$result = mysql_query ("SELECT name From table");
while ($row = mysql_fetch_array($result));
{
?>
<select NAME="venue" size="1">
<option value="something i guess">results</option>
how do i get the results in the drop down menu???
-
try this:
PHP Code:
<select name="select">
<?
$qry = mysql_query("SELECT name FROM table");
while($arr = mysql_fetch_array($qry)){
echo " <option value='$arr[name']>$arr[name]\n";
}
?>
</select>
-
Quote:
Originally posted by kows
try this:
PHP Code:
<select name="select">
<?
$qry = mysql_query("SELECT name FROM table");
while($arr = mysql_fetch_array($qry)){
echo " <option value='$arr[name']>$arr[name]\n";
}
?>
</select>
I get this error
Parse error: parse error, expecting `']'' in /home/httpd/vhosts/site.com/httpdocs/history.php on line 86
-
I used this the other day....worked fine for me:
PHP Code:
$resultat1 = mysql_query("SELECT sNavn FROM Sted",$db);
while($arr1 = mysql_fetch_array($resultat1)){
$sNavn = stripslashes($arr1["sNavn"]);
echo " <option value=\"$arr1[sNavn]\">$arr1[sNavn]\n";
}
-
typing stuff up on the fly makes for syntax errors, you should've been able to fix it yourself.
PHP Code:
<select name="select">
<?
$qry = mysql_query("SELECT name FROM table");
while($arr = mysql_fetch_array($qry)){
echo " <option value='$arr[name]'>$arr[name]\n";
}
?>
</select>
-
I had to look twice to see that one...:D....well I guess both ways work...
-
sweet got it working... problem is the form is
<form method="POST" action="gallery.php">
PHP Code:
<select size="1" name="cats" style="border-style: solid; border-width: 1">
<option selected>-- Please select a category --</option>
<?php
while ($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row["cat_id"];?>"><font face="Verdana" size="1"><?php echo $row["cat_name"];?></option>
<?php
}
?>
</select>
and the gallery.php script
PHP Code:
$result = mysql_query ("SELECT * From gallery_cats where cat_id = $cat_id");
this is not a vaild search option... how do i fix this??
-
Quote:
Originally posted by kiwis
sweet got it working... problem is the form is
<form method="POST" action="gallery.php">
PHP Code:
<select size="1" name="cats" style="border-style: solid; border-width: 1">
<option selected>-- Please select a category --</option>
<?php
while ($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row["cat_id"];?>"><font face="Verdana" size="1"><?php echo $row["cat_name"];?></option>
<?php
}
?>
</select>
and the gallery.php script
PHP Code:
$result = mysql_query ("SELECT * From gallery_cats where cat_id = $cat_id");
this is not a vaild search option... how do i fix this??
If gallery_cats are the table and cat_id is an atribute, then try this:
PHP Code:
$result = mysql_query ("SELECT * From gallery_cats where cat_id = ".$cat_id."");
-
I suggest always putting your database search values within single quotes.
PHP Code:
$result = mysql_query("SELECT * FROM gallery_cats WHERE cat_id='$cat_id'");
And, also, try using <?=$var;?> to echo your variables instead of <?php echo $var;?>. It just makes it look nice/saves time.