beaner_06 Posted March 10, 2010 Share Posted March 10, 2010 I am getting an error when trying to display my variables inside the table. Also, do I need the while statement? <? $result = mysql_query("SELECT * FROM computers"); while($row = mysql_fetch_array($result)) { } mysql_close($conn); ?> <html> <body> <table cellpadding='2' cellspacing='2' border='1'> <tr> <td><?=$row['comp_id'];</td> <td>=$row['comp_brand'];</td> <td>=$row['comp_price'];</td> ?> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/194824-beginner-php-code/ Share on other sites More sharing options...
TeddyKiller Posted March 10, 2010 Share Posted March 10, 2010 Use the proper <?php ?> tags. Not short hand "<? ?>" Next time when you recieve errors, post the exact error you are getting. <?=$row['comp_id'];</td> <td>=$row['comp_brand'];</td> <td>=$row['comp_price'];</td> ?> Sorry, but what the hell? This may be to a better use to you. <?php echo $row['comp_id].'</td> <td>'.$row['comp_brand'].'</td> <td>'.$row['comp_price'].';</td> ?> Quote Link to comment https://forums.phpfreaks.com/topic/194824-beginner-php-code/#findComment-1024435 Share on other sites More sharing options...
beaner_06 Posted March 10, 2010 Author Share Posted March 10, 2010 My bad. The only error code it was giving was the line #. Thanks for the help. EDIT After I tried usiing: <table cellpadding='2' cellspacing='2' border='1'> <tr> <?php echo $row['comp_id].'</td> <td>'.$row['comp_brand'].'</td> <td>'.$row['comp_price'].';</td> ?> </tr> </table> I am getting: Parse error: syntax error, unexpected '/' on the PHP line Quote Link to comment https://forums.phpfreaks.com/topic/194824-beginner-php-code/#findComment-1024443 Share on other sites More sharing options...
KevinM1 Posted March 10, 2010 Share Posted March 10, 2010 Fixed code: <?php $result = mysql_query("SELECT * FROM computers"); ?> <html> <head></head> <body> <table cellpadding='2' cellspacing='2' border='1'> <?php while($row = mysql_fetch_assoc($result)) { echo "<tr><td>{$row['comp_id']}</td><td>{$row['comp_brand']}</td><td>{$row['comp_price']}</td></tr>"; } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/194824-beginner-php-code/#findComment-1024446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.