daveoffy Posted May 20, 2009 Share Posted May 20, 2009 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"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/158840-solved-problem-pulling-data-from-database-i-am-sure-it-is-right/ Share on other sites More sharing options...
garethhall Posted May 20, 2009 Share Posted May 20, 2009 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)); Link to comment https://forums.phpfreaks.com/topic/158840-solved-problem-pulling-data-from-database-i-am-sure-it-is-right/#findComment-837815 Share on other sites More sharing options...
MadTechie Posted May 20, 2009 Share Posted May 20, 2009 Erm.. whats with the infinitive loop ? while (1) { Link to comment https://forums.phpfreaks.com/topic/158840-solved-problem-pulling-data-from-database-i-am-sure-it-is-right/#findComment-837816 Share on other sites More sharing options...
daveoffy Posted May 20, 2009 Author Share Posted May 20, 2009 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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/158840-solved-problem-pulling-data-from-database-i-am-sure-it-is-right/#findComment-837822 Share on other sites More sharing options...
MadTechie Posted May 20, 2009 Share Posted May 20, 2009 change $result = @mysql_query($qry); to $result = mysql_query($qry) or die(mysql_error()); and your see why Link to comment https://forums.phpfreaks.com/topic/158840-solved-problem-pulling-data-from-database-i-am-sure-it-is-right/#findComment-837824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.