prcollin Posted July 28, 2008 Share Posted July 28, 2008 I had a version of this question up before but i cant find it. I know how to fetch arrays, but how do i get the results to populate in a drop down selection box. I have the code for the fetch array. mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM clients");while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 Something like.... <?php if ($result = mysql_query("SELECT * FROM clients")) { if (mysql_num_rows($result)) { echo "<form>"; echo " <select name=\"clients\">"; while($row = mysql_fetch_array($result)) { echo " <option value=\"{$row['id']}\">{$row['FirstName']} {$row['LastName']}</option>"; } echo " </select>"; echo "</form>"; } } ?> Quote Link to comment Share on other sites More sharing options...
prcollin Posted July 28, 2008 Author Share Posted July 28, 2008 Something like.... <?php if ($result = mysql_query("SELECT * FROM clients")) { if (mysql_num_rows($result)) { echo "<form>"; echo " <select name=\"clients\">"; while($row = mysql_fetch_array($result)) { echo " <option value=\"{$row['id']}\">{$row['FirstName']} {$row['LastName']}</option>"; } echo " </select>"; echo "</form>"; } } ?> THis shows up on the screen "; while($row = mysql_fetch_array($result)) { echo " {$row['client_fname']} {$row['client_lname']}"; } echo " "; echo ""; } } ?> This is the code i used modified for my names <?php include "clientconnect.php"; mysql_select_db('greencut_customercenter', $con); if ($result = mysql_query("SELECT * FROM clients")) { if (mysql_num_rows($result)) { echo "<form>"; echo " <select name=\"clients\">"; while($row = mysql_fetch_array($result)) { echo " <option value=\"{$row['client_lname']}\">{$row['client_fname']} {$row['client_lname']}</option>"; } echo " </select>"; echo "</form>"; } } ?> and my last questions would be how to get the form to perform an action. Can i just change echo "<form>"; to echo "<form action = "updateclient.php method="post">"; and how do i add the button for submitting here? Quote Link to comment Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 THis shows up on the screen "; while($row = mysql_fetch_array($result)) { echo " {$row['client_fname']} {$row['client_lname']}"; } echo " "; echo ""; } } ?> it shouldn't. As for the rest of your question, seems you need some basic tutorials. theres a link in my signiture to a free book (Hudzilla), within that is an entire chapter devoted to php and forms. Quote Link to comment Share on other sites More sharing options...
adam84 Posted July 28, 2008 Share Posted July 28, 2008 and my last questions would be how to get the form to perform an action. Can i just change echo "<form>"; to echo "<form action = "updateclient.php method="post">"; and how do i add the button for submitting here? Like this echo "<form action=\"updateclient.php\" method=\"post\">"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.