kbloem Posted August 20, 2010 Share Posted August 20, 2010 Hi, i've got the folowing search query but now i want to add an image location in the database and the result has to contain an image instead of the record name. I don't know how to start.... A link to a manual would also be great.... <?php $con = mysql_connect("localhost","admin",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("model", $con); $qry = "SELECT * FROM eigenschappen WHERE 1=1"; if (isset($_POST['merk']) && trim($_POST['merk']) != "") { $qry .= " AND merk='" . mysql_real_escape_string($_POST['merk']). "'"; } if (isset($_POST['cpu']) && $_POST['cpu'] != "0") { // "0" ipv 0 $qry .= " AND cpu='" . mysql_real_escape_string($_POST['cpu']). "'"; } if (isset($_POST['hdd']) && $_POST['hdd'] != "0") { // "0" ipv 0 $qry .= " AND hdd='" . mysql_real_escape_string($_POST['hdd']). "'"; } $result = mysql_query($qry) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['merk'] . " " . $row['cpu'] . " " . $row['hdd']; echo "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/ Share on other sites More sharing options...
kickstart Posted August 20, 2010 Share Posted August 20, 2010 Hi Do you mean you want a list of the records, each with an image? If so (assuming the column is called image_name <?php $con = mysql_connect("localhost","admin",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("model", $con); $qry = "SELECT * FROM eigenschappen WHERE 1=1"; if (isset($_POST['merk']) && trim($_POST['merk']) != "") { $qry .= " AND merk='" . mysql_real_escape_string($_POST['merk']). "'"; } if (isset($_POST['cpu']) && $_POST['cpu'] != "0") { // "0" ipv 0 $qry .= " AND cpu='" . mysql_real_escape_string($_POST['cpu']). "'"; } if (isset($_POST['hdd']) && $_POST['hdd'] != "0") { // "0" ipv 0 $qry .= " AND hdd='" . mysql_real_escape_string($_POST['hdd']). "'"; } $result = mysql_query($qry) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo '<img src="'.$row['image_name'].'/>'.$row['merk'] . " " . $row['cpu'] . " " . $row['hdd']; echo "<br />"; } ?> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/#findComment-1101560 Share on other sites More sharing options...
kbloem Posted August 20, 2010 Author Share Posted August 20, 2010 Thanks That works.... Now one more question. This is my input script.... <tr> <td>4. </td> <td><label for="image_name">Location:</label></td> <td><input style="width:300px" id="image_name" name="image_name" /></td> </tr> Can i browse to the file name with a browse button and when i select te filename it copies it to the image_location in the database as full path length? Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/#findComment-1101583 Share on other sites More sharing options...
kickstart Posted August 20, 2010 Share Posted August 20, 2010 Hi Don't think so, as that is giving rather too much control over your machine to a web site. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/#findComment-1101586 Share on other sites More sharing options...
kbloem Posted August 20, 2010 Author Share Posted August 20, 2010 Ok, one last question... When the search option has more than one result only one images shows. It generates a html output like this... <img toshiba.jpg="" images="" src="images/dell.jpg>< img src="> When it generates an output for only one records it looks good. <img src="images/acer.jpg"> Why is that? Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/#findComment-1101593 Share on other sites More sharing options...
kickstart Posted August 20, 2010 Share Posted August 20, 2010 Hi I think that might be my fault. I have missed a " on the following line echo '<img src="'.$row['image_name'].'"/>'.$row['merk'] . " " . $row['cpu'] . " " . $row['hdd']; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/#findComment-1101596 Share on other sites More sharing options...
kbloem Posted August 20, 2010 Author Share Posted August 20, 2010 Thanks Keith, that was it. Greetings from Holland Quote Link to comment https://forums.phpfreaks.com/topic/211260-sql-result-in-images/#findComment-1101597 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.