calling a specific image based on a search
Moderator: General Moderators
calling a specific image based on a search
I have a simple sql database with items in it. Each item has its unique identifier 'itemno' column
If I search for a specific item via search.html the result gets processed via results.php.
On the results page, I would like to be able to show an image of the item / items that match the search criteria.
The images can be stored in a folder within htdocs and named 1.jpg, 2.jpg etc to concur with itemno 1. itemno 2 etc.
Apologies for the question but I am only on day 3 of php learning but after extensive searching I am at a dead end.
I hope you can help and thanks in advance
Okanem
If I search for a specific item via search.html the result gets processed via results.php.
On the results page, I would like to be able to show an image of the item / items that match the search criteria.
The images can be stored in a folder within htdocs and named 1.jpg, 2.jpg etc to concur with itemno 1. itemno 2 etc.
Apologies for the question but I am only on day 3 of php learning but after extensive searching I am at a dead end.
I hope you can help and thanks in advance
Okanem
I am asking for the code needed to select an image from a folder based on search criteria.
i.e. if a user enters 1 in the search.html form and clicks submit, I want results.php to choose the appropriate image for item 1 and display it along with the rest of Item 1's text description.
The text results are working fine, I just don't know how to return 1.jpg
Sorry if its not worded very well
Okanem
i.e. if a user enters 1 in the search.html form and clicks submit, I want results.php to choose the appropriate image for item 1 and display it along with the rest of Item 1's text description.
The text results are working fine, I just don't know how to return 1.jpg
Sorry if its not worded very well
Okanem
I have the code for the search.html page
ALSO I have the code for the results.php page
*************************************
***************************************************
If you search for Item 1 using the search page, the results page links to the mysql db cws and returns the Item No ; Item Description ; Garment Spec ; NSN Range from the Items table.
Based on the user choosing 1 as the variable searchterm and clicking the search button, I want the results page to also return a .jpg of Item 1 to the browser. The .jpgs are stored in a folder within htdocs.
I need code which I can insert into results.php to return the .jpg
Okanem
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CWS Database</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {
font-size: 24px;
font-weight: bold;
color: #FFFFFF;
}
-->
</style></head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"><p> </p>
<table width="450" border="0" cellpadding="0" cellspacing="0" bgcolor="#000066">
<tr>
<td><div align="center" class="style1">CWS SEARCH PAGE </div></td>
</tr>
</table>
<br>
<br>
<table width="450" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="top">
<td width="225" height="60"><div align="left">Search for an Item</div></td>
<td width="225" height="60"><form name="form1" method="post" action="itemsearchresults.php">
<div align="left">
<input name="searchterm" type="text" id="searchterm">
<input type="submit" value="Search">
</div>
</form></td>
</tr>
<tr align="center" valign="top">
<td width="225" height="60"><div align="left">Search for an NSN </div></td>
<td width="225" height="60"><form name="form1" method="post" action="nsnsearchresults.php">
<div align="left">
<input name="searchterm" type="text" id="searchterm">
<input type="submit" value="Search">
</div>
</form></td>
</tr>
<tr align="center" valign="top">
<td width="225" height="60"><div align="left">Search for a G' Spec Code </div></td>
<td width="225" height="60"><form name="form1" method="post" action="gssearchresults.php">
<div align="left">
<input name="searchterm" type="text" id="searchterm">
<input type="submit" value="Search">
</div>
</form></td>
</tr>
<tr align="center" valign="top">
<td width="225" height="60"><div align="left">Search for a Pattern Code </div></td>
<td width="225" height="60"><div align="left"></div></td>
</tr>
<tr align="center" valign="top">
<td width="225" height="60"><div align="left">Search Item Descriptions </div></td>
<td width="225" height="60"><form name="form1" method="post" action="itemdescsearchresults.php">
<div align="left">
<input name="searchterm" type="text" id="searchterm">
<input type="submit" value="Search">
</div>
</form></td>
</tr>
<tr align="center" valign="top">
<td width="225" height="60"><div align="left">Search BOM's </div></td>
<td width="225" height="60"><div align="left"></div></td>
</tr>
</table>
<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle">
Page Views - <?php
$filename = "count_file.txt";
echo $data = (file_exists($filename)) ? file_get_contents($filename)+1 : 1;
$file = fopen($filename,w); fwrite($file, $data); fclose($file);
?>
</td>
</tr>
</table>
<p> </p>
<p> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>ALSO I have the code for the results.php page
*************************************
Code: Select all
<html>
<head>
<title>CWS Item Search Results</title>
</head>
<body>
<h1>CWS Item Search Results</h1>
<?php
// create short variable names
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli('localhost', '***', '***', '***');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select * from items where ".itemno." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo '<p>Number of items found: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo '<p><strong>'.($i+1).'. Item No: ';
echo htmlspecialchars(stripslashes($row['itemno']));
echo '</strong><br />Item Description: ';
echo stripslashes($row['itemdesc']);
echo '<br />Garment Spec: ';
echo stripslashes($row['gscode']);
echo '<br />NSN Range: ';
echo stripslashes($row['nsnrange']);
echo '</p>';
}
$result->free();
$db->close();
?>
<a href="newitem.html">Back to add another Item</a></body><br>
<a href="search.html">Search for an item</a></body><br>
<a href="index.html">Back to index</a></body><br>
</body>
</html>If you search for Item 1 using the search page, the results page links to the mysql db cws and returns the Item No ; Item Description ; Garment Spec ; NSN Range from the Items table.
Based on the user choosing 1 as the variable searchterm and clicking the search button, I want the results page to also return a .jpg of Item 1 to the browser. The .jpgs are stored in a folder within htdocs.
I need code which I can insert into results.php to return the .jpg
Okanem
Thanks pickle -
I have added a column to the items table called image
I have put 1.jpg in the items table under the image column against item 1 and so forth
I really have no idea how to incorporate the 1.jpg filename in an <img> tag within my results.php code.
Please assume the 1.jpg is in the root dir along with the html and php files.
Can someone show me the code to call the file 1.jpg.
Okanem
I have added a column to the items table called image
I have put 1.jpg in the items table under the image column against item 1 and so forth
I really have no idea how to incorporate the 1.jpg filename in an <img> tag within my results.php code.
Please assume the 1.jpg is in the root dir along with the html and php files.
Can someone show me the code to call the file 1.jpg.
Okanem
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
the code would look like this
place that where you are looping through your database results.
Code: Select all
echo '<img src="'.$row['image'].'">';