/    Sign up×
Community /Pin to ProfileBookmark

How to make php script output valid xhtml

I have a problem where basically, My PHP works fine but it doesn’t output valid strict xhtml. Even though the lists of posts which this script outputs looks ok in my browser it doesn’t validate. It’s closing the <li> tags when they should stay open to receive the next inline <ul> tags. Can anyone help? I’m thinking this is going to take some heavy if statement to resolve.
Cheers

[code=php] if (!isset($_GET[‘MBID’])) exit;
mysql_connect(“”, “”, “”);
mysql_select_db(“”);

function showpost(&$parent) {
extract($parent, EXTR_PREFIX_ALL, “msg”);
$msg_DateSubmitted = date(“jS of F Y”, $msg_DateSubmitted);
echo “t<li><a href=”read.php?Msg=$msg_ID”>$msg_Title</a> posted by <a href=”mailto:$msg_Email”>$msg_Poster</a> on $msg_DateSubmitted</li>n”;
$result = mysql_query(“SELECT ID, Title, Poster, Email, DateSubmitted FROM mbmsgs WHERE MBID = {$_GET[‘MBID’]} AND Parent = $msg_ID ORDER BY DateSubmitted DESC;”);

if (mysql_num_rows($result)) {
echo “t<ul>n”;
while ($row = mysql_fetch_assoc($result)) {
showpost($row);
}
echo “t</ul>n”;
}
}

$result = mysql_query(“SELECT Name FROM mblist WHERE ID = {$_GET[‘MBID’]};”);
if (!$result) exit;
if (!mysql_num_rows($result)) exit;

extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, ‘mb’);
echo “<h2>$mb_Name</h2>n<hr />n”;
echo “<p>Select a post from below</p><p>n”;

$result = mysql_query(“SELECT ID, Title, Poster, Email, DateSubmitted FROM mbmsgs WHERE MBID = {$_GET[‘MBID’]} AND Parent = 0 ORDER BY DateSubmitted DESC;”);
if (!$result) exit;
if (!mysql_num_rows($result)) {
echo “<p>This messageboard has no posts.</p>”;
} else {
echo “<ul>n”;
while ($row = mysql_fetch_assoc($result)) {
showpost($row);
}
echo “</ul>n”;
}
?>[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehFeb 07.2006 — Can you post a link?
Copy linkTweet thisAlerts:
@NogDogFeb 07.2006 — Perhaps this?
[code=php]
function showpost(&$parent) {
extract($parent, EXTR_PREFIX_ALL, "msg");
$msg_DateSubmitted = date("jS of F Y", $msg_DateSubmitted);
echo "t<li><a href="read.php?Msg=$msg_ID">$msg_Title</a> posted by <a href="mailto:$msg_Email">$msg_Poster</a> on $msg_DateSubmitted";
$result = mysql_query("SELECT ID, Title, Poster, Email, DateSubmitted FROM mbmsgs WHERE MBID = {$_GET['MBID']} AND Parent = $msg_ID ORDER BY DateSubmitted DESC;");

if (mysql_num_rows($result)) {
echo "t<ul>n";
while ($row = mysql_fetch_assoc($result)) {
showpost($row);
}
echo "t</ul>n";
}
echo "</li>n";
}
[/code]
Copy linkTweet thisAlerts:
@DoppleauthorFeb 07.2006 — Yeah that worked NogDog. Thanks. Although I also had to remove the <p> tags. I didn't realise lists could go between paragraph tags.

You live and learn.

Thanks
Copy linkTweet thisAlerts:
@bokehFeb 07.2006 — lists can also contain paragraphs... [CODE]<li><p>paragraph</p></li>[/CODE]
×

Success!

Help @Dopple 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.18,
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,
)...