Jump to content

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


daveoffy

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";
  }
}
?>

 

 

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.