Jump to content

showing results from database


Porkie

Recommended Posts

<?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

 

Link to comment
https://forums.phpfreaks.com/topic/163129-showing-results-from-database/
Share on other sites

	<?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

 

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");

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

Archived

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

×
×
  • 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.