Jump to content

How do i make images appear when making a search from a MYSQL database?


usman07

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
?>

Link to comment
Share on other sites

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
    }

Link to comment
Share on other sites

  • 3 weeks later...
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.