siwelis Posted June 15, 2007 Share Posted June 15, 2007 $sql = mysql_query("SELECT * FROM shopping_products ORDER BY product_id "); $string1 = '<table>'. '<tr><td>WAZZA!</td></tr>'; while($row = mysql_fetch_array($sql){ $string1 .= '<tr><td>THAT'S RIGHT!</td></tr>'. '<tr><td>THAT'S RIGHT!</td></tr>'; } $string1 .= </table>' echo $string1; All I get from this is "<table> <tr><td>WAZZA!</td></tr> </table>" Why isn't the while putting the info into the string? Does anyone have some insight on another way to do this? I've also tried making it $string1 .= while($row = mysql_fetch_array($sql){ '<tr><td>THAT'S RIGHT!</td></tr>'. '<tr><td>THAT'S RIGHT!</td></tr>'; } and that doesn't seem to help either. Link to comment https://forums.phpfreaks.com/topic/55726-problems-while-looping/ Share on other sites More sharing options...
per1os Posted June 15, 2007 Share Posted June 15, 2007 Syntax error here: while($row = mysql_fetch_array($sql)) { $string1 .= '<tr><td>THAT'S RIGHT!</td></tr>'. '<tr><td>THAT'S RIGHT!</td></tr>'; } //and here $string1 .= '</table>'; For starts. The second one wouldn't work as you cannot have the while inside a variable declaration. Third, make sure there is data coming from the query, that shopping_products does contain some rows, because a query will return true and return no results. I would suggest putting this at top for testing purposes error_reporting(E_ALL); As your code is not showing the syntax errors. It may help out. Link to comment https://forums.phpfreaks.com/topic/55726-problems-while-looping/#findComment-275338 Share on other sites More sharing options...
simcoweb Posted June 15, 2007 Share Posted June 15, 2007 I like to do it like this: $sql = mysql_query("SELECT * FROM shopping_products ORDER BY product_id"); $numrows = mysql_num_rows($sql); if($numrows == 0){ echo "There are no results available."; } else { echo "<table><tr><td>WAZZA!</td></tr>"; // this is outside the loop while($row = mysql_fetch_array($sql)) { echo "<tr><td>THAT'S RIGHT!</td></tr>"; } echo "</table>"; // this is outside the loop } Link to comment https://forums.phpfreaks.com/topic/55726-problems-while-looping/#findComment-275350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.