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
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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.