UQ13A Posted June 17, 2009 Share Posted June 17, 2009 Another Question again How would i print my result(s) into drop down menus with a button if (isset($_GET['edit'])) { $s = $_SESSION['hello']; $gen = rand(1,1000); $gen1 = rand(1,1000); $gen2 = rand($gen,$gen1); $query = ("SELECT * FROM `car` WHERE owner = '$s'"); $result = mysql_query($query) or die(mysql_error()); $numresults = mysql_num_rows($result); if ($numresults == 0) { echo "You dont have any cars to edit"; exit; } else { $i=1; while($row = mysql_fetch_array($result)) { $make = $row['Make']; $model = $row['Model']; $id = $row['id']; print "<form action=\"edit.php\" method=\"GET\"><select name=\"edit\" class=\"textbox\" id=\"edit\"> <option value=\"Please Select\" selected=\"selected\">Please Select...</option> <option value=\"$model$make$id$gen2\">$models $makes</option> </select><br /> <input type=\"submit\" name=\"edit\" id=\"edit\" value=\"Edit Car\"/> </form>"; $i++; } } } When this script is ran it shows all the results but in differant menus, I need them in one thanks Link to comment https://forums.phpfreaks.com/topic/162644-php-loop-in-dropdown-menu/ Share on other sites More sharing options...
Goldeneye Posted June 18, 2009 Share Posted June 18, 2009 Simply take all the HTML code in the Print-Statement (except for the second <option></option> line) and put it outside the loop. <?php if (isset($_GET['edit'])) { $s = $_SESSION['hello']; $gen = rand(1,1000); $gen1 = rand(1,1000); $gen2 = rand($gen,$gen1); $query = ("SELECT * FROM `car` WHERE owner = '$s'"); $result = mysql_query($query) or die(mysql_error()); $numresults = mysql_num_rows($result); if ($numresults == 0) { echo "You dont have any cars to edit"; exit; } else { $i=1; print "<form action=\"edit.php\" method=\"GET\"><select name=\"edit\" class=\"textbox\" id=\"edit\"> <option value=\"Please Select\" selected=\"selected\">Please Select...</option>"; while($row = mysql_fetch_array($result)) { $make = $row['Make']; $model = $row['Model']; $id = $row['id']; print "<option value=\"$model$make$id$gen2\">$models $makes</option>"; $i++; } print "</select><br /> <input type=\"submit\" name=\"edit\" id=\"edit\" value=\"Edit Car\"/> </form>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/162644-php-loop-in-dropdown-menu/#findComment-858560 Share on other sites More sharing options...
UQ13A Posted June 18, 2009 Author Share Posted June 18, 2009 thanks i'll give it a try sorry for late reply fell asleep yesterday Link to comment https://forums.phpfreaks.com/topic/162644-php-loop-in-dropdown-menu/#findComment-858982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.