tags:

views:

156

answers:

4

Here is my code, part of it is working flawlessly while the other isn't.

<?php
$query  = "Select * from Query ORDER BY time DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
?>

<span class="hotspot" onmouseover="tooltip.show('<center><b><?php echo $row['name'] ?></b></center>');" onmouseout="tooltip.hide();">
<?php
echo "<img src='/" . $row['name'] . ".gif'> ";
}
?>

Now there is like 100+ rows, the second $row['name'] is working fine with the loop, but the first one is using the First rwos result for every result.
Any Solution?

A: 

have you tried assigning $row['name'] to a variable then use the variable to build the HTML?

used2could
Tried that didn't work
Joseph Robidoux
A: 

I'm not sure if this matters but you may want to put a semicolon in your first piece of echo code:

<?php echo $row['name']; ?>
Joe Philllips
Tried that didn't work
Joseph Robidoux
It is of course a fatal error to leave off the semicolon elsewhere, but PHP doesn't mind if you omit it for the last command before a closing PHP tag.
Alex JL
A: 

I don't spot any obvious errors-- try adding one line code so it echos the $row['name'] earlier in the loop, which might help you understand better what's going on. See below:

<?php
$query  = "Select * from Query ORDER BY time DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo $row['name']."<br>";      // <-------- ADD THIS LINE
?>

<span class="hotspot" onmouseover="tooltip.show('<center><b><?php echo $row['name'] ?></b></center>');" onmouseout="tooltip.hide();">
<?php
echo "<img src='/" . $row['name'] . ".gif'> ";
}
?>
Eric
A: 

I found the problem. The end </span> was after the loop.

Joseph Robidoux
Yeah... I was rewriting it to clean it up a bit for you, and that was one of my questions, actually. "Does this span end anywhere?".That wouldn't change the value of `$row['name']` that was being printed out, though it may make it appear that way. Be sure to view your actual HTML to see what's going on. You might also wish to use the W3 Validator or the HTML Validator extension for Firefox.
Alex JL