...

View Full Version : PHP Won't echo?



Webmonkey
08-04-2008, 04:46 PM
Hello,

For some reason, php won't echo the $row[2], so I assume there is something wrong with my code. If you help, I will be highly grateful.

THanks



<?php
ob_start();
require_once('connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>
<div class="header">
<div class="global-nav">
<p>Welcome to my blog! I've not really finished the CMS yet so bear with me! Latest Post: Why Marc is sexy.</p>
</div></div>
<div id="container">
Introduction - <a href="#">Hide / Show</a><br />
Blah Blah<br /.
<?php
$query = mysql_query("SELECT `id`, `title`, `body` FROM `posts`") or die(mysql_error());
while($row = mysql_fetch_array($query, MYSQL_NUM)) {
echo $row[2];

print_r($row);
}
?>

<a href="#"><h2>Why Marc is sexy</h2></a> Post by <a href="#">Steven</a> on 16th November 2008<br />
<p>This is the post. Marc is sexy because the new stuff on www.codesleeprepeat.com, his website. Come on, admint he's aweosme!</p>
<br /><br /
<h2>Why Marc is sexy</h2> Post by <a href="#">Steven</a> on 16th November 2008<br />
<p>This is the post. Marc is sexy because the new stuff on www.codesleeprepeat.com, his website. Come on, admint he's aweosme!</p>
</div>
</body>
</html>

mlseim
08-04-2008, 04:56 PM
See this ....

http://www.php-mysql-tutorial.com/php-mysql-select.php

I think you might try echo $row[0];

derzok
08-04-2008, 04:58 PM
What does print_r show?

Webmonkey
08-04-2008, 05:00 PM
Thanks both of you for your quick replies.

The print_r shows:

1 [1] => Why is Steven so hot? [2] => Not sure... someone please say! )

CFMaBiSmAd
08-04-2008, 05:02 PM
Edit: Never mind, you posted while I was writing this.

More importantly, you need to tell us what you see in front of you when you try this.

Does the portion of the page before the query show in the browser and does the portion of the page after the php logic show in the browser?

Webmonkey
08-04-2008, 05:05 PM
Yes, everything is shown except the echo from the database. Even the print_r array is displayed corrently.

Thanks

Webmonkey
08-04-2008, 05:39 PM
I have now got this working. Thanks for your help everyone invloved.

djm0219
08-04-2008, 05:44 PM
What did you find that resolved it?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum