joshgarrod Posted July 23, 2007 Share Posted July 23, 2007 Hi everyone. I have a search script on my website that when returning results doesn't show the corresponding image, where am I going wrong please? I would like preferably for it to display as a thumbnail linking to the larger image in a seperate page. I cannot get it to work. Could someone have a look for me please. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Search for spares</title> <style type="text/css"> <!-- .style1 {font-family: Arial, Helvetica, sans-serif} --> </style> </head> <body> <h2 class="style1">Search</h2> <form action="<?=$PHP_SELF?>" method="post" name="search" class="style1"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="StockDescription">Stock description</option> <Option VALUE="ID">Stock ID</option> <Option VALUE="StockNumber">Stock number</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <p class="style1"> <?php //This is only displayed if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><hr>"; //If they did not enter a search term we give them an error if ($find == "") { echo "<p>Please enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("lgfdhh", "dfgh", "dfghgh") or die(mysql_error()); mysql_select_db("sto21") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $find_array = explode(" ", $find); $find_sql = ""; // init foreach ($find_array as $temp) $find_sql .= "upper($field) LIKE '%$temp%' OR "; // note only need to do the substr once, the second time was removing the other %' $find_sql = substr($find_sql, 0, -3); // throw away last OR statement $sql = "SELECT * FROM stock WHERE $find_sql"; $data = mysql_query($sql) OR DIE("SQL Was: " . $sql . "<br />ERROR: " . mysql_error()); $sql = "SELECT * FROM stock"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // It is now safe to use $result. } else { // No results found. } } else { // Query failed. Good place to debug, eg; echo "Query failed<br />" . $sql . "<br />" . mysql_error(); } $fileName="searchLog.txt"; $fp=fopen($fileName, "a"); $search="$find - "; //with endline char $bytesWritten = fwrite ($fp, $search); if ($bytesWritten < 1) mail ("[email protected]", "problem writing to log", "eom");//if this fails, check directory permissions //And we display the results while($result = mysql_fetch_array( $data )) { echo "<b>Stock ID: </b>"; echo $result['ID']; echo "<br>"; echo "<b>Stock number: </b>"; echo $result['StockNumber']; echo "<br>"; echo "<b>Stock description: </b>"; echo $result['StockDescription']; echo "<br>"; echo "<b>Price: </b>"; echo $result['ItemPrice']; echo "<br>"; echo "<b>Image: </b>"; echo $result['<td align=center><a href="Image">"Image"</a></td>']; echo "<br>"; echo "<hr>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/61378-help-with-this-script-please/ Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 This code echo $result['<td align=center><a href="Image">"Image"</a></td>']; shouldnt be smth like: echo "<img src=\"{$result['imagePath']}\" />" Where 'imagePath' is the path to the thumbnail. You can put the whole thing between <a> tags to link it to the full size image. Hope i got it right and helped. Link to comment https://forums.phpfreaks.com/topic/61378-help-with-this-script-please/#findComment-305994 Share on other sites More sharing options...
joshgarrod Posted July 24, 2007 Author Share Posted July 24, 2007 It didnt work:( Link to comment https://forums.phpfreaks.com/topic/61378-help-with-this-script-please/#findComment-306102 Share on other sites More sharing options...
DeadEvil Posted July 24, 2007 Share Posted July 24, 2007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Search for spares</title> <style type="text/css"> <!-- .style1 {font-family: Arial, Helvetica, sans-serif} --> </style> </head> <body> <h2 class="style1">Search</h2> <form action="<?=$PHP_SELF?>" method="post" name="search" class="style1"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="StockDescription">Stock description</option> <Option VALUE="ID">Stock ID</option> <Option VALUE="StockNumber">Stock number</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <p class="style1"> <?php $find = $_POST['find']; //This is only displayed if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><hr>"; //If they did not enter a search term we give them an error if ($find == "") { echo "<p>Please enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("lgfdhh", "dfgh", "dfghgh") or die(mysql_error()); mysql_select_db("sto21") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $find_array = explode(" ", $find); $find_sql = ""; // init foreach ($find_array as $temp) $find_sql .= "upper($field) LIKE '%".$temp."%' OR"; // note only need to do the substr once, the second time was removing the other %' $find_sql = substr($find_sql, 0, -3); // throw away last OR statement $sql = "SELECT * FROM stock WHERE $find_sql"; $data = mysql_query($sql) OR DIE("SQL Was: " . $sql . "<br />ERROR: " . mysql_error()); $sql = mysql_query("SELECT * FROM stock"); $num = mysql_num_rows($sql); if ($num > 0) { // There's a result } else { // No results found. } $fileName="searchLog.txt"; $fp=fopen($fileName, "w+"); $search="$find - "; //with endline char $bytesWritten = fwrite ($fp, $search); if ($bytesWritten < 1) mail ("[email protected]", "problem writing to log", "eom");//if this fails, check directory permissions //And we display the results while($result = mysql_fetch_array( $data )) { echo "<b>Stock ID: </b>"; echo $result['ID']; echo "<br>"; echo "<b>Stock number: </b>"; echo $result['StockNumber']; echo "<br>"; echo "<b>Stock description: </b>"; echo $result['StockDescription']; echo "<br>"; echo "<b>Price: </b>"; echo $result['ItemPrice']; echo "<br>"; echo "<b>Image: </b>"; echo $result['<td align=center><a href="Image">"Image"</a></td>']; echo "<br>"; echo "<hr>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/61378-help-with-this-script-please/#findComment-306124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.