aleister1987 Posted May 30, 2010 Share Posted May 30, 2010 Hi all, I have a problem, Im not so hot on PHP but here goes. I have done a query and i want the info from my database(table) in table form in my php/html document. Here is what i have. Im also trying to echo an image stored in a sql database. At present its just a blank screen mainly. <?php $host="..."; // Host name $username="..."; // Mysql username $password="..."; // Mysql password $db_name="..."; // Database name $tbl_name="..."; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Retrieve data from database $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); //Puts it into an array while($info=mysql_fetch_array( $sql )) { echo "<table width='800' border='1' cellspacing='1' cellpadding='3'>"; echo "<tr>"; echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Model No:</font></td>"; echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'> </font></td>"; echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Description:</font></td>"; echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Price:</font></td>"; echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Stock:</font></td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $info['model'] . " </td>"; echo "<td>"<img src=http://www.swiftelectrical.net/images/".$info['photo'] ."></td>"; echo "<td>" . $info['product'] . " </td>"; echo "<td>" . $info['description'] . " </td>"; echo "<td>" . $info['price'] . " </td>"; echo "<td>" . $info['stock'] . " </td>"; echo "</tr>"; echo "</table>"; } mysql_close (); ?> Link to comment https://forums.phpfreaks.com/topic/203341-php-query-error/ Share on other sites More sharing options...
ohdang888 Posted May 30, 2010 Share Posted May 30, 2010 read pages 8 and 9 on this tutorial: http://www.phpriot.com/articles/images-in-mysql/8 Link to comment https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065319 Share on other sites More sharing options...
aleister1987 Posted May 30, 2010 Author Share Posted May 30, 2010 Thanks for that. However, I followed another tutorial to be able to upload images. I can echo the image fine when i take all my html off the page. I have added the die function on the query. But... I still have the original problem, the table itself doesn't show on the page. Link to comment https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065324 Share on other sites More sharing options...
shino Posted May 30, 2010 Share Posted May 30, 2010 In your while it should be $result in the function and not $sql. Have you tried this? Link to comment https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065331 Share on other sites More sharing options...
phant0m Posted May 30, 2010 Share Posted May 30, 2010 You need to make s sperate page for the image, or output it as base64 encoded, which is not the option you should go for Just create another script, that only outputs the image from the database. You have to pay attention to the header setting: Content-Type: image/jpeg or what ever you need. Then, you will have an image tag on your original page, whose src attribute points to your newly created script for the image. Link to comment https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065341 Share on other sites More sharing options...
ohdang888 Posted May 30, 2010 Share Posted May 30, 2010 make the image tag this : <img src="http://www.yourdomain.com/images/show.php?id=<?php echo ID of the row of the IMAGE ?> Link to comment https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.