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>"; ?> 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* 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. 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'"; } ?> 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. Link to comment https://forums.phpfreaks.com/topic/53938-solved-help/#findComment-266730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.