Connecting Tech Pros Worldwide Forums | Help | Site Map

...it only prints the letter "m"

kiqyou_vf
Guest
 
Posts: n/a
#1: Jul 17 '05
does anyone know why this code:

if ($query= "SELECT * FROM ryanBlog WHERE entryNum=5"){
print "<p class=../style1>cool</p>";
}else{
print "<p class=../style1>not cool</p>";
}

if($run= mysql_query($query)){
$row= "mysql_fetch_array($run)";

print '<table width="50%" border="0" cellspacing="5"
cellpadding="5">';

print "<p class=../style1>wonderful</p>";
}else{ print "not wonderful";
}

print "
<tr>
<td bgcolor=#FF9966><font class=header>{$row['title']} </font>
&nbsp;&nbsp;&nbsp; <font class=entry> {$row['dateTime']} &nbsp;&nbsp;
{$row['entryNum']} &nbsp;&nbsp; <a
href=edit_entry.php?entryNum={$row['entryNum']}>edit</a></font></td>
</tr>
<tr>
<td><font class=entry>{$row['entry']}</font></td>
</tr>";

print '</table>'

would result in the letter "m" taking the place of $row[''] ?? STRANGE!


Chris Hope
Guest
 
Posts: n/a
#2: Jul 17 '05

re: ...it only prints the letter "m"


kiqyou_vf wrote:
[color=blue]
> does anyone know why this code:
>
> if ($query= "SELECT * FROM ryanBlog WHERE entryNum=5"){
> print "<p class=../style1>cool</p>";
> }else{
> print "<p class=../style1>not cool</p>";
> }[/color]

Note that the test above will always evaluate as true because you are
assigning a value in the test, ie it will always print "cool"
[color=blue]
> if($run= mysql_query($query)){
> $row= "mysql_fetch_array($run)";[/color]

You are assigning the text string "mysql_fetch_array($run)" to $row. The
code should read:

$row= mysql_fetch_array($run);

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Daniel Tryba
Guest
 
Posts: n/a
#3: Jul 17 '05

re: ...it only prints the letter "m"


kiqyou_vf <sorensong@gmail.com> wrote:
....[color=blue]
> $row= "mysql_fetch_array($run)";[/color]
....[color=blue]
> <td><font class=entry>{$row['entry']}</font></td>[/color]
....[color=blue]
> would result in the letter "m" taking the place of $row[''] ?? STRANGE![/color]

Not that strange. $row is a string containing "mysql...."
$row['foo'] tries to get the numeric 'foo' index of $row (a string is an array
of chars), (int)'foo' evalutates to 0 thus the first char of $row (which
is 'm').

fix: $row=mysql_fetch_assoc($run);

kiqyou_vf
Guest
 
Posts: n/a
#4: Jul 17 '05

re: ...it only prints the letter "m"


wonderful. thanks for the help when and when not to use quotes kind of
throws me off... but i'll get used to it. thanks for the help.

Geoff Berrow
Guest
 
Posts: n/a
#5: Jul 17 '05

re: ...it only prints the letter "m"


I noticed that Message-ID:
<1109818567.957635.307740@l41g2000cwc.googlegroups .com> from kiqyou_vf
contained the following:
[color=blue]
> <tr>
> <td bgcolor=#FF9966><font class=header>{$row['title']} </font>
>&nbsp;&nbsp;&nbsp; <font class=entry> {$row['dateTime']} &nbsp;&nbsp;
>{$row['entryNum']} &nbsp;&nbsp; <a
>href=edit_entry.php?entryNum={$row['entryNum']}>edit</a></font></td>
> </tr>
> <tr>
> <td><font class=entry>{$row['entry']}</font></td>
> </tr>";
>
>print '</table>'[/color]

Man, that's fuggly html...

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Closed Thread


Similar PHP bytes