Porkie Posted June 21, 2009 Share Posted June 21, 2009 <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $sql = mysql_query("SELECT * FROM Bands "); while($row = mysql_fetch_array($sql)) how can i echo the results so they are put in a table going from right to left instead of going down to up ? Example I want it going like this, Apple Avacado Bannana ......... Cheers Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/ Share on other sites More sharing options...
Ken2k7 Posted June 21, 2009 Share Posted June 21, 2009 Well it's not rocket science. Learn a bit of HTML. <?php echo '<table><tr>'; while ($row = mysql_fetch_assoc($sql)) { echo '<td>'; // print your stuff here echo '</td>'; } echo '</tr></table>'; Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860673 Share on other sites More sharing options...
Porkie Posted June 21, 2009 Author Share Posted June 21, 2009 <?php echo '<table><tr>'; while ($row = mysql_fetch_array($sql)) { echo '<td>'; echo 'name'; echo '</td>'; } echo '</tr></table>'; $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $sql = mysql_query("SELECT * FROM gg_video "); ?> with that code i get this error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myuklive/public_html/New directory/taster.php on line 108 on this line while ($row = mysql_fetch_array($sql)) { also i only want it to show five results so how would i do that ? cheers Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860705 Share on other sites More sharing options...
wildteen88 Posted June 21, 2009 Share Posted June 21, 2009 Umm, you put your code in then wrong order. Your while loop needs be placed after this line $sql = mysql_query("SELECT * FROM gg_video "); If you only want your query to return 5 results then use the LIMIT clause in your query $sql = mysql_query("SELECT * FROM gg_video LIMIT 5"); Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860730 Share on other sites More sharing options...
Porkie Posted June 21, 2009 Author Share Posted June 21, 2009 cheers mate, echo '<table><tr>'; while ($row = mysql_fetch_array($sql)) { echo '<td>'; echo $row['name']; echo 'http://img.youtube.com/vi/['videoid']/default.jpg'; echo '</td>'; } echo '</tr></table>'; how would i get this line to work? echo 'http://img.youtube.com/vi/['videoid']/default.jpg'; videoid getting the data from my database? cheers Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860744 Share on other sites More sharing options...
wildteen88 Posted June 21, 2009 Share Posted June 21, 2009 You'd use $row['videoid'] echo 'http://img.youtube.com/vi/'.$row['videoid'].'/default.jpg'; Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860749 Share on other sites More sharing options...
chmpdog Posted June 21, 2009 Share Posted June 21, 2009 You would have to put it in an array before you can echo it like that $row = mysql_fetch_array($result, MYSQL_BOTH); Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860754 Share on other sites More sharing options...
wildteen88 Posted June 21, 2009 Share Posted June 21, 2009 You would have to put it in an array before you can echo it like that $row = mysql_fetch_array($result, MYSQL_BOTH); MySQL_fetch_array returns both a numerical and associative array. Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860764 Share on other sites More sharing options...
Porkie Posted June 21, 2009 Author Share Posted June 21, 2009 ok so where would i have to put that line? and how could i make that url it creates become an actual image? thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860767 Share on other sites More sharing options...
corbin Posted June 21, 2009 Share Posted June 21, 2009 An image tag with an src attribute.... echo '<img src="'.$image_path.'" />'; Hopefully this doesn't offend you, but before trying to use PHP to output HTML, perhaps you should learn HTML. Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-860769 Share on other sites More sharing options...
chmpdog Posted June 22, 2009 Share Posted June 22, 2009 Hopefully this doesn't offend you, but before trying to use PHP to output HTML, perhaps you should learn HTML. I second that notion, php basically wraps itself around html Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-861023 Share on other sites More sharing options...
Ken2k7 Posted June 22, 2009 Share Posted June 22, 2009 I second that notion, php basically wraps itself around html It does? Hmm... never knew that. Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-861069 Share on other sites More sharing options...
chmpdog Posted June 24, 2009 Share Posted June 24, 2009 I second that notion, php basically wraps itself around html It does? Hmm... never knew that. well if your creating a webpage, which Im assuming he is Quote Link to comment https://forums.phpfreaks.com/topic/163129-showing-results-from-database/#findComment-862816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.