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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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