/    Sign up×
Community /Pin to ProfileBookmark

Printing mysql into table rows

Hi there,
I have some code based upon tizag’s tutorial at [url]http://www.tizag.com/mysqlTutorial/mysqlselect.php[/url] which I am trying to alter.

Essentiallyu, what I am trying to do is show the output from four fields in a table.

This is the php:

[code=php]<?php
$query = “SELECT * FROM `cast`”;
$castlist = mysql_query($query);
//mysql_close();
echo “<table border=’1′>”;
echo “<tr> <th>First Name</th> <th>Second Name</th> <th>Age</th> <th>Role</th></tr>”;
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $castlist )) {
// Print out the contents of each row into a table
echo “<tr><td>”;
echo $row[‘fname’];
echo “</td><td>”;
echo $row[‘sname’];
echo “</td></tr>”;
echo $row[‘type’];
echo “</td></tr>”;
echo $row[‘age’];
echo “</td></tr>”;
}

echo “</table>”;
?>[/code]

Currently, the script creates the correct headers, and two columns (fname, sname), but the shows the output from the last two outside the table.

Can anyone show me where I am going wrong?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@YelgnidrocMay 17.2009 — </tr> ends the row, and you have too many </tr>'s
Copy linkTweet thisAlerts:
@AliHurworthauthorMay 17.2009 — Yes, thank-you!!
×

Success!

Help @AliHurworth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...