usman07 Posted April 9, 2012 Share Posted April 9, 2012 I currently have a MYSQL database which works and is connected, at the moment is brings up information from the database but beside the information from the database I also want images to appear. How do i do this? Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/ Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 Where are the images coming from? Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335730 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 I dont really know how to set it up? I dont know where to put the images etc, are they suppose to be somehow in the MYSQL database or could they be in a directory e.g. cutouts/Homepage. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335737 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 Typically, the images are stored in a directory and the file paths are stored in the database. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335743 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 ahh right ok, how do i go about setting file paths in the database? Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335750 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 create a varchar type field named whatever and insert the file paths. So if you have an image at /some/file/path/image.jpg, that is what will go into that field, along with any other corresponding image data that you want. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335751 Share on other sites More sharing options...
Jessica Posted April 9, 2012 Share Posted April 9, 2012 Are you trying to have a specific image come up based on the search results, or the same image next to each result? your question is kind of vague. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335752 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 Yeah i'm trying to have a specific image come up based on the search results Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335754 Share on other sites More sharing options...
Jessica Posted April 9, 2012 Share Posted April 9, 2012 Okay then continue with the above method. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335756 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335758 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 Ok I have done that, what do i do now? this is a image of mysql table of 1 of my entries, is this right? Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335770 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 looks right. Now you need to grab that data from the db using a select statement. Have you attempted a query yet? Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335774 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 No i haven't yet, dunno how to really. php is kinda new to me. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335777 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 Here is some Pseudo code to get you going: $sql = 'SELECT * from table'; $query = mysql_query($sql) or die(mysql_error() . '<br />' . $sql); while($row = mysql_fetch_assoc($query)) { ?> <img src="<?php echo $row['images']; ?>" /> <?php } this will simply display each image in the table, you will need to tweak it to suit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335779 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 thank you very much for your help, i really do appreciate it. where abouts would i be placing that code in my php? heres my php code: <?php $server = "mysql10.000webhost.com"; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use // Query database $result = mysql_query("SELECT * FROM Properties"); if (!$result) { echo "Error running query:<br>"; trigger_error(mysql_error()); } elseif(!mysql_num_rows($result)) { // no records found by query. echo "No records found"; } else { $i = 0; echo '<div style="font-family:helvetica; font-size:15px; padding-left:15px; padding-top:20px;">'; while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo "Displaying record $i<br>\n"; echo "<b>" . $row['id'] . "</b><br>\n"; // Where 'id' is the column/field title in the database echo $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo $row['Property_type'] . "<br>\n"; // as above echo $row['Number_of_bedrooms'] . "<br>\n"; // .. echo $row['Purchase_type'] . "<br>\n"; // .. echo $row['Price_range'] . "<br>\n"; // .. } echo '</div>'; } mysql_close($con); // Close the connection to the database after results, not before. ?> Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335780 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 again, this code will need to be tweaked so it looks right: while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo "Displaying record $i<br>\n"; echo "<b>" . $row['id'] . "</b><br>\n"; // Where 'id' is the column/field title in the database echo $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo $row['Property_type'] . "<br>\n"; // as above echo $row['Number_of_bedrooms'] . "<br>\n"; // .. echo $row['Purchase_type'] . "<br>\n"; // .. echo $row['Price_range'] . "<br>\n"; // .. echo '<img src="'. $row['images'] .'" />'; //image } Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335784 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 thats brilliant, it appears, how would i get it to appear beside the text rather than below? Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335791 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 remove the <br>\n from the previous line. You can add CSS to the image also. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335798 Share on other sites More sharing options...
usman07 Posted April 9, 2012 Author Share Posted April 9, 2012 How would i apply css to the image, would I give it an ID then apply the css in my style.css or do i apply it within the php code? Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335802 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 the first statement, add either a class or an id (depending upon how many images you want the css to affect) and style it in an external css page. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1335805 Share on other sites More sharing options...
deragoku Posted April 27, 2012 Share Posted April 27, 2012 Simply each image is displayed in the table, you will need to be adjusted to suit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/260626-how-do-i-make-images-appear-when-making-a-search-from-a-mysql-database/#findComment-1340948 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.