Jump to content

Help to display an image from path stored in mysql field


AlexisK

Recommended Posts

Hello there . I have a little problemI want to make a movie database.In mysql i create a table

create table movies (id int, name varchar(100), cover varchar(100), primary key(id));
Next i use insert into movies ................ to insert data in table . In cover field i insert the path of cover . ( covers\cover1.jpg)The php code to see the contents of movies table
<?php$con = mysql_connect("localhost","root","12345");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("db_movies", $con);$result = mysql_query("SELECT * FROM movies"); while($row = mysql_fetch_array($result)) { echo $row['id'] . " " . $row['name'] . " " . $row['cover']; echo "<br />"; }mysql_close($con);?>
The result is "1 movie name cover\cover1.jpgHow can i take id movie name and the picture ???????
Link to comment
Share on other sites

you'll have to use PHP to output HTML during while loop. here's an example of how to create a table (towards the bottom of the page). http://www.w3schools.com/php/php_mysql_select.aspOf course you'll have to adapt it to your own needs, but it should give you a framework nonetheless.

Link to comment
Share on other sites

Unless I misunderstand the question, all you need to do is wrap the path data in an image tag as you loop through the rows:while($row = mysql_fetch_array($result)){ print "$row['name']<br /> <img src=\"$row['cover']\"><br />";}

Link to comment
Share on other sites

You understand corectly but i take a wrong messageParse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\XAMPP\xampp\htdocs\movies.php on line 17line 17 is the print "$row['name']<br /> <img src=\"$row['cover']\"><br />";

Link to comment
Share on other sites

shouldn't it be something like:

print $row['name'] . "<br/> <img src=\"" . $row['cover'] . "\"></br>";

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...