2

I have this code which should search for pictured in mysql database, am not sure if it is working,

I want to get the images the user search for and post them in the html, can i do this?

Here is my code

<?php require('connect.php'); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //connect to the database //-query the database table $sql="SELECT * FROM cards WHERE name LIKE '%$searchQuery'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $name = $row['name']; $id = $row['id']; } } else{ echo "<p>Please enter a search query</p>"; } } } ?> 
5
  • Do you store image's path in database ? Commented Jun 21, 2015 at 8:36
  • @SulthanAllaudeen yea, images stored like this, filename/pictureName.jpg Commented Jun 21, 2015 at 9:15
  • May i know the coloumn Name that you use Commented Jun 21, 2015 at 9:22
  • @SulthanAllaudeen column name is 'name' Commented Jun 21, 2015 at 9:25
  • I have posted the answer, I thought you would use image as the name :) I will update my answer :) Commented Jun 21, 2015 at 9:26

1 Answer 1

1

To display the image [Where you have stored the image's path in db]

You shall just echo the coloumn with the image tag

echo "<img src =".$row['name'].">"; 

Note :

You should point the image the path where the image is stored in the files

Some thing like

echo "<img src ='assets/images/".$row['name']."'>" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.