Jump to content

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?

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.