zavin Posted April 30, 2010 Share Posted April 30, 2010 Why is cars in the following code an undefined variable? $result = mysql_query("SELECT * FROM `carlot`"); $howmanyitems = 0; while($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($line['buyable'] == 1){ $cars .= "<td width='25%' align='center'><img src='". $line['image']."' width='100' height='100' style='border: 1px solid #333333'><br> ". car_popup($line['name'], $line['id']) ."<br>$". $line['cost'] ."<br><a href='carlot.php?buy=".$line['id']."'>[buy]</a></td>"; $howmanyitems = $howmanyitems + 1; if ($howmanyitems == 3){ $cars.= "</tr><tr>"; $howmanyitems = 0; } } } Link to comment https://forums.phpfreaks.com/topic/200262-notice-undefined-variable/ Share on other sites More sharing options...
OOP Posted April 30, 2010 Share Posted April 30, 2010 Hi, can you please post the complete message that you are getting? regards Link to comment https://forums.phpfreaks.com/topic/200262-notice-undefined-variable/#findComment-1050942 Share on other sites More sharing options...
gclx Posted April 30, 2010 Share Posted April 30, 2010 Because you are adding stuff (.=) to a variable that doesn't exist. $cars = ""; at the beginning of your code will fix your error. Or change error type to something less strict . Link to comment https://forums.phpfreaks.com/topic/200262-notice-undefined-variable/#findComment-1050943 Share on other sites More sharing options...
zavin Posted April 30, 2010 Author Share Posted April 30, 2010 Because you are adding stuff (.=) to a variable that doesn't exist. $cars = ""; at the beginning of your code will fix your error. Or change error type to something less strict . That was it. It's always the small stuff thanks. Link to comment https://forums.phpfreaks.com/topic/200262-notice-undefined-variable/#findComment-1050945 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.