Help with code that outputs rows from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Help with code that outputs rows from DB

Post by nickman013 »

Hello,

I am outputting rows from a DB, but I am having trouble becasue I need the rows to change color when they are highlighted, but I am having a major apostrophe problem.

My code now.

Code: Select all

echo "<tr style="background-color:#CCCCCC;" 
  onMouseOver="this.className='highlight'">"; 
echo "<td align=left width=100 valign=top><font size=2>".$row4['name']."</font></td>"; 
echo "<td align=left><font size=2>".$row4['comment']."</font></td>";
echo '<td><font size=2><a href=/deletecomment.php?id='.$row4['id'].'>Delete Comment</a></td></tr>';
Can anybody make the first echo work for me, ive been tryign for like a hour.

Thanks so much!!!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Help with code that outputs rows from DB

Post by Luke »

nickman013 wrote:

Code: Select all

echo "<tr style="background-color:#CCCCCC;"  onMouseOver="this.className='highlight'">"; 
echo "<td align=left width=100 valign=top><font size=2>".$row4['name']."</font></td>"; 
echo "<td align=left><font size=2>".$row4['comment']."</font></td>";
echo '<td><font size=2><a href=/deletecomment.php?id='.$row4['id'].'>Delete Comment</a></td></tr>';
Try that
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Thanks that worked!!

But now I have a client side question, but I dont wanna open a new thread for this question.

The question is, do you know why the background color doesnt change when the mouse is on it.

The code is this.

Code: Select all

echo "<tr style=\"background-color:#CCCCCC;\"  onMouseOver=\"background-color:#8888FF;\">";
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Because that's not the way you do it...

Look here:
http://www.w3schools.com/dhtml/dhtml_css.asp
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

or you could do something like this (stolen from phpmyadmin)

Code: Select all

table tr.odd:hover{
    background-color:   #CCFFCC;
}
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I did the one above, but it doesnt seem to work.

My code now.

Code: Select all

<style type=text/css>
table tr.odd:hover{ 
background-color:#CCFFCC; 
}
</style>
<table border=0>
	<tr><td><b>NAME</b></td><td><b>COMMENT</b></td></tr>
<?
$username2= "muot_report";  
$password2= "password";  
$database2= "muot_report";  
$connection2 = mysql_connect('localhost',$username2,$password2);  
mysql_select_db($database2); 
$sql4 = "SELECT * FROM `comments` WHERE who =" . $_GET['id'] . ""; 
$result4 = mysql_query($sql4) or die(mysql_error()); 
while($row4 = mysql_fetch_array($result4)) {
echo "<tr>"; 
echo "<td align=left width=100 valign=top><font size=2>".$row4['name']."</font></td>"; 
echo "<td align=left><font size=2>".$row4['comment']."</font></td>"; 
echo '<td><font size=2><a href=/deletecomment.php?cmtid='.$row4['id'].'&muotid='.$_GET['id'].'>Delete Comment</a></td></tr>';
} mysql_close($connection2); 
?>
</table>
THANKS SO MUCH!
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I got it. I re-read the CSS and didnt relize I had to label the rows.

Thanks so Much!!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Image
Post Reply