Jump to content

Beginner PHP Code


beaner_06

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/194824-beginner-php-code/
Share on other sites

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> 
?>

Link to comment
https://forums.phpfreaks.com/topic/194824-beginner-php-code/#findComment-1024435
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/194824-beginner-php-code/#findComment-1024443
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/194824-beginner-php-code/#findComment-1024446
Share on other sites

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.