Jump to content

SQL result in images


kbloem

Recommended Posts

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 />";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/211260-sql-result-in-images/
Share on other sites

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

Thanks  :D 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?

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.