joshuaer Posted September 13, 2012 Share Posted September 13, 2012 (edited) Hello I am trying to figure out how to create a drop down that pulls from 3 rows, I can pull a single value with the code below but I cannot figure out how to mull the other values <?include("sql.php"); include("auth.php"); $UID = $_SESSION['UID'];$sql="SELECT * FROM users where UID='$UID' AND Cnumber != ''";$result=mysql_query($sql);$options="";while ($row=mysql_fetch_array($result)) { $id=$row["Nname"]; $thing=$row["Nname"]; $options.="<OPTION VALUE=\"$id\">".$thing;}?><SELECT NAME=Nname><OPTION VALUE=0>Choose<?=$options?></SELECT> so in the dropdown I would need it to pull for each option Nname CNumber address Edited September 13, 2012 by joshuaer Link to comment Share on other sites More sharing options...
Ingolme Posted September 13, 2012 Share Posted September 13, 2012 The WHERE clause is limiting your query results. You can omit it to return everything that's in the database. Link to comment Share on other sites More sharing options...
kanchatchai Posted September 13, 2012 Share Posted September 13, 2012 (edited) $options.="<OPTION VALUE=\"$id\">".$thing."</OPTION>"; Edited September 13, 2012 by kanchatchai Link to comment Share on other sites More sharing options...
joshuaer Posted September 13, 2012 Author Share Posted September 13, 2012 How would I display the 3 rows in the dropdown? With the current code I have it only shows one row Nname but in the dropdown I need Nname Cname address to all be displayed Thanks Link to comment Share on other sites More sharing options...
rahultailwal Posted September 13, 2012 Share Posted September 13, 2012 Hi use the below code. As i guessed, you want to show three columns value show in drop down. so just put the three column values by giving one space.Hope you want the same.<?include("sql.php"); include("auth.php"); $UID = $_SESSION['UID'];$sql="SELECT * FROM users where UID='$UID' AND Cnumber != ''";$result=mysql_query($sql);$options="";while ($row=mysql_fetch_array($result)) { $id=$row["Nname"]; $thing=$row["Nname"]; $options.="<OPTION VALUE=\"$id\">".$thing." ".$row["CNumber"]"." ".$row["address"]."</option>";}?><SELECT NAME=Nname><OPTION VALUE=0>Choose<?=$options?></SELECT> Link to comment Share on other sites More sharing options...
joshuaer Posted September 14, 2012 Author Share Posted September 14, 2012 thanks for the reply with the code above I am gttin this error Parse error: syntax error, unexpected ';' in /homepages/37/d381229304/htdocs/go-servers/icloud/addressbook.php on line 17 <?phpinclude("sql.php");include("auth.php");$UID = $_SESSION['UID'];$sql="SELECT * FROM users where UID='$UID' AND Cnumber != ''";$result=mysql_query($sql);//$options="";while ($row=mysql_fetch_array($result)) {$id=$row["Nname"];$thing=$row["Nname"];[/b][b]$options.="<OPTION VALUE=\"$id\">".$thing." ".$row["CNumber"]."".$row["address"]."</option>";}?><SELECT NAME=Nname><OPTION VALUE=0>Choose<?=$options.?></SELECT> Link to comment Share on other sites More sharing options...
joshuaer Posted September 14, 2012 Author Share Posted September 14, 2012 forget that I had accidently put a . after the $option Link to comment Share on other sites More sharing options...
joshuaer Posted September 14, 2012 Author Share Posted September 14, 2012 one more question, with the drop down selecting the 3 rows I am using this as a sort of address book. The users load the Nname Cname and address on another page then when they are filling out a form I want them to be able to use the drop down to make a selection. So is it possible to have it post that information it is pulling back into the database into the 3 different rows? Nname Cname address Link to comment Share on other sites More sharing options...
kanchatchai Posted September 14, 2012 Share Posted September 14, 2012 (edited) create form and post to other pageand select from $_POST value $sql="SELECT * FROM users where users.Nname='".$_POST["Name"]."'"; Edited September 14, 2012 by kanchatchai Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now