Jump to content

[SOLVED] problem pulling data from database? I am sure it is right.


Recommended Posts

I get an error pulling data from database. I am sure it is right. Also how can I limit it so it wont keep on looping, and it will stop after 10?

 

<?PHP
$Color = "#FFFFFF";
while (1) {
$qry = "SELECT * FROM `Sell` ORDER BY `sell_id` DESC LIMIT 10";
$result = @mysql_query($qry);
while($row = mysql_fetch_array($result)) {
$title = $row['title'];
$seller_id = $row['seller_id'];
$posted = $row['posted'];
$price = $row['price'];
$time = $row['time'];
echo '<div style="background-color: '.$Color.'; width: 200; height: 30;">'.$title;
  if ($Color == "#F1F3F6") {
  $Color = "#F8F9FA" ;
  }elseif ($Color == "#F8F9FA") {
  $Color = "#F1F3F6";
  }
}
}
?>

It is what I would do or something like that just count the loops and beak it when you want.

 

$qry = "SELECT * FROM `Sell` ORDER BY `sell_id` DESC LIMIT 10";

$result = @mysql_query($qry);

$row = mysql_fetch_array($result);

 

do{ $i++

if($i <= 10){

$title = $row['title'];

$seller_id = $row['seller_id'];

$posted = $row['posted'];

$price = $row['price'];

$time = $row['time'];

} else{

break;

}

}while($row = mysql_fetch_array($result));

I am sitll new with PHP.

 

I get this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt/www/site.com/buy.php on line 6

 

<?PHP
$Color = "#FFFFFF";
while (1) {
$qry = "SELECT * FROM `Sell` ORDER BY `sell_id` DESC LIMIT 10";
$result = @mysql_query($qry);
$row = mysql_fetch_array($result);
$title = $row['title'];
$seller_id = $row['seller_id'];
$posted = $row['posted'];
$price = $row['price'];
$time = $row['time'];
echo '<div style="background-color: '.$Color.'; width: 200; height: 30;">'.$title;
  if ($Color == "#F1F3F6") {
  $Color = "#F8F9FA" ;
  }elseif ($Color == "#F8F9FA") {
  $Color = "#F1F3F6";
  }
}
?>

 

 

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.