Jump to content

New: Search results


anevins

Recommended Posts

What I expect:

- The function to loop output all of the rows which match the search results.

 

The problems:

- Only 1 row is matched.

- Notice: Undefined index: id in G:\xampp\htdocs\xampp\dsa\search_func.php on line 57

- The image is not showing

 

Line 57:

$id = $_REQUEST['id'];

 

Entire Code:

<?php
/*  return the details of an employee
     parameter 
         empno - employee number
         
     eg empHTML.php?empno=7521
    This is  very basic  e.g no error checking      
*/

function search($dbc, $id) { 


if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) {

$terms = $_GET['terms'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server');

    $query = "SELECT * FROM stick, location, identification WHERE make LIKE '%$terms%' AND stick.sid = location.lid AND identification.stickID = stick.sid
AND identification.stickID = $id";
   
$result=mysqli_query($dbc,$query);	

   	$num_rows = mysqli_num_rows($result);

$output = Array();
   
    $image = mysqli_fetch_object($result);

if ($num_rows > 0){ 
			if($result=mysqli_query($dbc,$query)){

				$output[] = '<ul>';
				$output[] = '<li> Type: '.$image->make .'<br />Size: '.$image->size .$image->type .'<br />Colour: '.$image->colour .
				'<br /> Street Missing in: ' .$image->street.'<br />Town missing in: '.$image->town .'<br />City missing in: '.$image->city.'</li>';
				$output[] = '</ul>';

			}

return join('',$output);
}
else {
	echo "<h3>Sorry,</h3>";
	echo "<p>your search: "" .$terms. "" returned zero results</p>";
}


}
	else { 
	// Tell them to use the search form.
	echo '<p class="error">Please use the search form at the top of the window to search this site.</p>';
}
}
// connect
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// get the id from the URL
$id = $_REQUEST['id'];

print search($dbc, $id);
print "<img src='getPhoto.php?id=$id'/>";

// close the database
mysqli_close($dbc);			

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.