Any PHP Gurus here?
 

MegaSack DRAW - This year's winner is user - rgwb
We will be in touch

[Closed] Any PHP Gurus here?

5 Posts
5 Users
0 Reactions
77 Views
Posts: 74
Free Member
Topic starter
 

Having trouble getting php to display the content of a text field
from mySQL

$result = mysql_query($sql);
.
.
.
$row = (mysql_fetch_assoc($result));
.
.

$Content = $row['Content'];
.
.
echo $Content;


 
Posted : 22/08/2009 2:51 pm
Posts: 74
Free Member
Topic starter
 

Resolved!
used the mysql_result command instead.


 
Posted : 22/08/2009 3:17 pm
Posts: 7985
Free Member
 

Have you checked that you're actually getting something back?

[code]if (mysql_num_rows($result) == 0) {
echo "No rows returned.";
exit;
}[/code]

Nothing leaps out as wrong, but a quick guess would be to replace

[code]$Content = $row['Content'];[/code]

with

[code]$Content = $row["Content"];[/code]

I assume you're only expecting the one result back?


 
Posted : 22/08/2009 3:22 pm
Posts: 0
Free Member
 

In your first example you need to itterate over the associative array returned by mysql_fetch_assoc e.g.

$query = "select * from blah where something = somethingelse";

$result = mysql_fetch_assoc($query);

foreach ($row in $result) {
echo $row['column_1'];
}

If you want to see the value of any variable in PHP, use the print_r() command. e.g.

print_r($Content);

in your example would have shown you a string representation of your resultset.


 
Posted : 22/08/2009 3:52 pm
Posts: 0
Free Member
 

$Content = $row['Content'];
with
$Content = $row["Content"];

would only make a difference if the quoted string contained escapes like "\n", which are only translated with double quotes


 
Posted : 22/08/2009 4:11 pm
Posts: 0
Free Member
 

Or contained variables...


 
Posted : 22/08/2009 4:31 pm