Trium918 Posted June 2, 2007 Share Posted June 2, 2007 Ok, the code below is selecting an image for the database after the user selects an image name from the drop down menu. Before the user selects an option echo "No results found"; is displayed. I am trying to a have default value/image to display at first glance. The page should be set with an image before the user comes to the page. What am I looking over? <?php // initialize variable $searchType $searchtype = $_POST['searchtype']; // connect $sql = "SELECT * FROM members_images WHERE images_name='$searchtype'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { $images_name = $row['images_name']; echo "<img src=\"$images_name\" height=\"127\" width=\"170\" alt=\" \" />"; } } else { echo "No results found"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> Code for drop down menu <?php $query2 = "SELECT DISTINCT images_name FROM members_images"; $result2 = mysql_query($query2); $num_results2 = mysql_num_rows($result2); echo "<form name=\"auto\" action=\"edit_photo.php\" method=\"post\">"; echo "<select name=\"searchtype\" onChange=\"auto.submit();\"> <option>Select Images</option>"; for ($i = 0; $i < $num_results2; $i++) { $row = mysql_fetch_array($result2); echo "<option value=\"$row[images_name]\">$row[images_name]</option>\n"; } echo "</select>"; //echo "<input type=\"submit\" value=\"Submit\" />"; echo "</form>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53938-solved-help/ Share on other sites More sharing options...
Trium918 Posted June 2, 2007 Author Share Posted June 2, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/53938-solved-help/#findComment-266723 Share on other sites More sharing options...
marcus Posted June 2, 2007 Share Posted June 2, 2007 <?php // initialize variable $searchType $searchtype = $_POST['searchtype']; // connect $sql = "SELECT * FROM members_images WHERE images_name='$searchtype'"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $images_name = $row['images_name']; echo "<img src=\"$images_name\" height=\"127\" width=\"170\" alt=\" \" />"; } } else { echo "No results found"; } ?> Give that a go. Quote Link to comment https://forums.phpfreaks.com/topic/53938-solved-help/#findComment-266724 Share on other sites More sharing options...
dj-kenpo Posted June 2, 2007 Share Posted June 2, 2007 or catch it right away at the top <? $searchtype = $_POST['searchtype']; if ($searchtype == ""){ //defualt $sql = "SELECT * FROM members_images LIMIT 1"; }else{ // connect $sql = "SELECT * FROM members_images WHERE images_name='$searchtype'"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53938-solved-help/#findComment-266728 Share on other sites More sharing options...
Trium918 Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks to both! How can I send the name of the image to another page? I am having trouble doing that. Quote Link to comment https://forums.phpfreaks.com/topic/53938-solved-help/#findComment-266730 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.