Jump to content

Recommended Posts

Hello,

 

I am trying to retrieve and display data from a mysql table into a html table using php. I am using this code and it works successfully.

 

<?php
mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

 

However, I want $row['FirstName'] and $row['LastName'] to appear in the SAME cell of the html table, next to one another. How would I write the code for that, if it is possible

 

Thanks in advance!

mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'><tr><th>Name</th></tr>";
while($row = mysql_fetch_array($result))  {  
echo "<tr>";  echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']"</td>";  
echo "</tr>";  
}
echo "</table>";
mysql_close($con);
?>

mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'><tr><th>Name</th></tr>";
while($row = mysql_fetch_array($result))  {  
echo "<tr>";  echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']"</td>";  
echo "</tr>";  
}
echo "</table>";
mysql_close($con);
?>

 

I don't think that works, I keep receiving the same error as before :-\

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'

 

No where in your first post did you say anything about a parse error!  Post your ENTIRE script, that is the only way to deal with parse errors. (Include the acutal error also, there should be a line number in it.)

No where in your first post did you say anything about a parse error!  Post your ENTIRE script, that is the only way to deal with parse errors. (Include the acutal error also, there should be a line number in it.)

 

I tried a similar code (not the code I posted)

 

I put this and got a parse error

echo "<td>" . $row['FirstName'] . " . $row['LastName']"</td>"

;

 

Then I tried your code too and received a parse error

echo "<td>" . $row['FirstName'] . ' ' . $row['Last_Name']"</td>";

this line

. $row['LastName']"</td>";  

 

Is missing a '.'

 

try

<?php
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'><tr><th>Name</th></tr>";
while($row = mysql_fetch_array($result))  {  
echo "<tr>";  echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']. "</td>";  
echo "</tr>";  
}
echo "</table>";
mysql_close($con);
?>

 

this line

. $row['LastName']"</td>";  

 

Is missing a '.'

 

try

<?php
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'><tr><th>Name</th></tr>";
while($row = mysql_fetch_array($result))  {  
echo "<tr>";  echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']. "</td>";  
echo "</tr>";  
}
echo "</table>";
mysql_close($con);
?>

 

I apologize for that, I'm gonna have to get more sleep, and quit being mean to people!

this line

. $row['LastName']"</td>";  

 

Is missing a '.'

 

try

<?php
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'><tr><th>Name</th></tr>";
while($row = mysql_fetch_array($result))  {  
echo "<tr>";  echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']. "</td>";  
echo "</tr>";  
}
echo "</table>";
mysql_close($con);
?>

 

I apologize for that, I'm gonna have to get more sleep, and quit being mean to people!

 

Thank you so much!

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.