Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.