Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 03:36 AM
jm
Guest
 
Posts: n/a
Default stumped by this php database behavior

Consider:

while ($j < $num2) {
$parent_id=mysql_result($result2,$j,"parent_id");
$fam_first_name=mysql_result($result2,$j,"fam_firs t_name");
$fam_age=mysql_result($result2,$j,"fam_age");
echo "it is $parent_id";
echo "<tr id=$parent_id>";
echo "<td></td>";
echo "<td >$fam_first_name</td>";
echo "<td>$fam_age</td>";
echo "</tr>";
++$j;
}

The line that says "it is $parent_id" will print the variable.
The next parent id will skip one if it has two of the same values. I
know this may not make sense, but:

it is 1
it is 3
it is 3
it is 6


but the second three from above will never be in the tr id= tag. i
hope this makes sens. It just doesn't print in the tag if it has two
rows.
thanks.





  #2  
Old July 17th, 2005, 03:36 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: stumped by this php database behavior

jm wrote:
(snip)[color=blue]
> The line that says "it is $parent_id" will print the variable.
> The next parent id will skip one if it has two of the same values. I
> know this may not make sense, but:
>
> it is 1
> it is 3
> it is 3
> it is 6
>
>
> but the second three from above will never be in the tr id= tag. i
> hope this makes sens. It just doesn't print in the tag if it has two
> rows.[/color]

Maybe you have something extra in $parent_id.

Do
<?php
echo "<pre>it is [$parent_id]</pre>";
?>

to verify that.

In your browser the string "it is 3" (notice *two* spaces)
is shown as "it is 3" (notice *one* space)


Happy bug hunting :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
  #3  
Old July 17th, 2005, 03:36 AM
jm
Guest
 
Posts: n/a
Default Re: stumped by this php database behavior

Pedro Graca <hexkid@hotpop.com> wrote in message news:<buitsv$ieneh$1@ID-203069.news.uni-berlin.de>...[color=blue]
> jm wrote:
> (snip)[color=green]
> > The line that says "it is $parent_id" will print the variable.
> > The next parent id will skip one if it has two of the same values. I
> > know this may not make sense, but:
> >
> > it is 1
> > it is 3
> > it is 3
> > it is 6
> >
> >
> > but the second three from above will never be in the tr id= tag. i
> > hope this makes sens. It just doesn't print in the tag if it has two
> > rows.[/color]
>
> Maybe you have something extra in $parent_id.
>
> Do
> <?php
> echo "<pre>it is [$parent_id]</pre>";
> ?>
>
> to verify that.
>
> In your browser the string "it is 3" (notice *two* spaces)
> is shown as "it is 3" (notice *one* space)
>
>
> Happy bug hunting :-)[/color]

Thanks. Actually, I found that I had to separate the string on three
different lines:

so, for example:

echo "<td id=";
echo $parent_id;
echo ">";

then it would print. Bizarre. I used to run into these quirks with
ASP (classic) too.
  #4  
Old July 17th, 2005, 03:40 AM
Juha Suni
Guest
 
Posts: n/a
Default Re: stumped by this php database behavior

jm wrote:[color=blue]
> Thanks. Actually, I found that I had to separate the string on three
> different lines:
>
> so, for example:
>
> echo "<td id=";
> echo $parent_id;
> echo ">";
>
> then it would print. Bizarre. I used to run into these quirks with
> ASP (classic) too.[/color]

Cleaner and faster to write would be just to do
echo "<td id=" . $parent_id . ">";

Or even for more performance (although not noticeable):
echo '<td id=' . $parent_id . '>';

And finally, to avoid html-problems if the $parent_id happens to contain
spaces (you never can be too sure), do:

echo '<td id="' . $parent_id . '">';

HTH

--
Suni

  #5  
Old July 17th, 2005, 03:40 AM
Tim Van Wassenhove
Guest
 
Posts: n/a
Default Re: stumped by this php database behavior

On 2004-01-22, Juha Suni <juha.suni@ilmiantajat.fi> wrote:[color=blue]
> jm wrote:[color=green]
>> Thanks. Actually, I found that I had to separate the string on three
>> different lines:
>>
>> so, for example:
>>
>> echo "<td id=";
>> echo $parent_id;
>> echo ">";
>>
>> then it would print. Bizarre. I used to run into these quirks with
>> ASP (classic) too.[/color]
>
> Cleaner and faster to write would be just to do
> echo "<td id=" . $parent_id . ">";
>
> Or even for more performance (although not noticeable):
> echo '<td id=' . $parent_id . '>';
>
> And finally, to avoid html-problems if the $parent_id happens to contain
> spaces (you never can be too sure), do:
>
> echo '<td id="' . $parent_id . '">';[/color]

As what html concerns, values of an attribute must be put between " " or
' '. Thus <td id='value'> is valid too.


Oh and the last option echo "<td id='{$parent_id}'/>";

--
http://home.mysth.be/~timvw
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.