PHP Table problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

PHP Table problem

Post by Tassadduq »

i have created a simple table with two rows and three columns and three variables.
i want to echo my three variables in the columns of first row.
but when i echo these variables in the columns it generates an error
that the syntax of table is incorrect
error is

Parse error: syntax error, unexpected '<' in C:\wamp\www\table.php on line 19

here the all coding of my page



<html>
<head>
<?php /* Start of HEAD Section */ ?>
<title>PHP Page<?php echo $page ?></title>
<meta name = "description" content= "This is my first own PHP scripted page"
<?php /*End of HEAD Section*/ ?>
</head>
<?php /*Start of Body Section */ ?>
<body>
<?php echo "Here is a method to echo the variables in table" ?>
<?php //Start of Table ?>
<?php
$First = "Tassadduq";
$Last = "Hussain";
$RollNo = 623;
?>
<?php
echo "<table width='80%' border='1'>";
<tr>
<td>echo "$First";</td>
<td>echo "$Last";</td>
<td>echo "RollNo";</td>
</tr>
<tr>
<td>Sample Text</td>
<td>Sample Text</td>
<td>Sample Textt</td>
</tr>
</table>
?>
<?php //End of Table ?>
</body>
<?php /*End of Body Section */ ?>



where is the mistake in table.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Table problem

Post by requinix »

Maybe highlighting will help you see the problem?

Code: Select all

<?php
echo "<table width='80%' border='1'>";
<tr>
<td>echo "$First";</td>
<td>echo "$Last";</td>
<td>echo "RollNo";</td>
</tr>
<tr>
<td>Sample Text</td>
<td>Sample Text</td>
<td>Sample Textt</td>
</tr>
</table>
?>
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

Re: PHP Table problem

Post by Tassadduq »

i have changed the code to following but it generates the same error



<html>
<head>
<?php /* Start of HEAD Section */ ?>
<title>PHP Page<?php echo $page ?></title>
<meta name = "description" content= "This is my first own PHP scripted page"
<?php /*End of HEAD Section*/ ?>
</head>
<?php /*Start of Body Section */ ?>
<body>
<?php echo "Here is a method to echo the variables in table" ?>
<?php //Start of Table ?>
<?php
$First = "Tassadduq";
$Last = "Hussain";
$RollNo = 623;
?>
<?php
echo "<table width='80%' border='1'>";
<tr>
<td>echo "$First";</td>
<td>echo "$Last";</td>
<td>echo "$RollNo";</td>
</tr>
<tr>
<td>Sample Text</td>
<td>Sample Text</td>
<td>Sample Textt</td>
</tr>
</table>
?>
<?php while(1); ?>
<?php //End of Table ?>
</body>
<?php /*End of Body Section */ ?>
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: PHP Table problem

Post by Frozenlight777 »

you're trying to put html within the php which won't work unless you echo the html for example:

Code: Select all

echo "<td>" . $firstname . "</td>";
or you can just close the php brackets when you're going to insert html then re-open them like:

Code: Select all

 
<?php
?>
<td><?php echo $firstname; ?> </td>
 
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

Re: PHP Table problem

Post by Tassadduq »

thanks for reply but
there is still problem.
will anyone right the whole code to this one simple
suppose we work in notepad and want to make a table through php script
before creating table i want to make 3 variables
1 $first - "First Name";
2 $last = "Last Name";
3 $rollno = "623";

and then create table with single rows and three columns
i want to display the three variables values in the first columns
in first column value of $first
in second column value of $last
and in the third column value of $rollno
so what will be the code for this????
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: PHP Table problem

Post by dude81 »

Paste this code exactly as it is. It should work

Code: Select all

 
<html>
<head>
<?php /* Start of HEAD Section */ ?>
<title>PHP Page<?php echo $page ?></title>
<meta name = "description" content= "This is my first own PHP scripted page"
<?php /*End of HEAD Section*/ ?>
</head>
<?php /*Start of Body Section */ ?>
<body>
<?php echo "Here is a method to echo the variables in table" ?>
<?php //Start of Table ?>
<?php
$First = "Tassadduq";
$Last = "Hussain";
$RollNo = 623;
?>
<table width='80%' border='1'>
<tr>
<td><?php echo "$First"; ?></td>
<td><?php echo "$Last"; ?></td>
<td><?php echo "RollNo"; ?></td>
</tr>
<tr>
<td>Sample Text</td>
<td>Sample Text</td>
<td>Sample Textt</td>
</tr>
</table>
 
<?php /* End of Table */ ?>
</body>
<?php /*End of Body Section */ ?>
 
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

Re: PHP Table problem

Post by Tassadduq »

Bundle of Thanks dude81
Post Reply