Jump to content

[SOLVED] Help!


Trium918

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.