wtfsmd Posted March 5, 2007 Share Posted March 5, 2007 Is there any way i could make a image for the alternating row colors instead of a strait bold color, for instance: $color1 = "#CCFFCC"; $color2 = "#BFD8BC"; Would there be anyway to link an image in there? I have tried it this way: $color1 = "<img src='..style1.jpg'>"; $color2 = "<img src='..style2.jpg'>"; I cant seem to get it right and i have tryed it a few different ways with no luck, could someone point me in the right direction please, thanks. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 What system are you using to display your results? Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 5, 2007 Author Share Posted March 5, 2007 What do you mean, my OS system, my database, or my code? Im useing Windows, Useing MySQL, and my code is from here http://www.phpfreaks.com/tutorials/5/0.php (of course modified to work with what i want it to do, but it works with colors so i wouldnt worry about what it may look like ..... i hope if you need it i can post it here looks kinda sloppy though haha) Or maybee none of those are what you asked Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 Oh.. I didn't realize you were talking about the tutorial Ok, you will need to modify both the $color lines AND the HTML below. For example: echo "<tr> <td width="110" style="background-image: url($row_color)" nowrap> $article_date</td> <td bgcolor="$row_color"> <a href="articles.php?cmd=full_article&article_id=$article_id">$article_title</a></td> </tr>"; [/code] I've now set a background image with CSS, rather than using bgcolor as in the original. Then you can set $color1 = 'style1.jpg' and $color2='style2.jpg' This is untested, so if anything strange happens, post here again Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 5, 2007 Author Share Posted March 5, 2007 Alright it didnt work, and here is my code ... maybee i didnt do it correctly <?php // Define your colors for the alternating rows (choose the color of the rows!) $color1 = 'style1.PNG'; $color2 = 'style2.PNG'; $row_count = 0; // Perform an statndard SQL query: $result = mysql_query("SELECT * FROM users") or die (mysql_error()); // We are going to use the "$row" method for this query. This is just my preference. while($row = mysql_fetch_array( $result )) { /* Now we do this small line which is basically going to tell PHP to alternate the colors between the two colors we defined above. */ $row_color = ($row_count % 2) ? $color1 : $color2; // Echo your table row and table data that you want to be looped over and over here. echo '<tr><th width="110" style="background-image: url($row_color)" nowrap><p align="center">'; echo "<a href='userpro.php?id="; echo $row['id']; echo "'>"; echo $row['username']; echo "</a></th>"; echo '<th style="background-image: url($row_color)">'; if($_SESSION['level'] == "2") { echo $row['email']; } else {if($row['show_email'] == "1") { echo $row['email']; } else { echo "hidden"; }} echo "</th>"; echo '<th style="background-image: url($row_color)">'; echo $row['urank']; echo "</th>"; echo '<th style="background-image: url($row_color)">'; echo $row['last_login']; echo "</th>"; // Add 1 to the row count $row_count++; } // Close out your table. echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 Hmm.. you have an awful lot of "th" there, and not much "tr" or "td". A table should look like this: <table> <thead> <tr> <th>Blah</th> </tr> </thead> <tbody> <tr> <td>123</td> </tr> </tbody> </table> The thead and tbody tags are optional, most people don't use them. "th" means "table header", "tr" means "table row", "td" means "table data" Quote Link to comment Share on other sites More sharing options...
todayme Posted March 5, 2007 Share Posted March 5, 2007 Try this below <? echo '<table width="100%" border="0" cellpadding="4" cellspacing="0"> <tr> <td width="110"><b>Lead Id</b></td> <td width="110"><b>Industry</b></td> <td><b>Location</b></td> </tr>'; // Define your colors for the alternating rows $color1 = "#CCFFCC"; $color2 = "#CCFF99"; $row_count = 0; // Perform an statndard SQL query: $sql_events = mysql_query("SELECT * FROM _Leads WHERE LINKID = '$userid'") or die(mysql_error()); // We are going to use the "$row" method for this query. This is just my preference. while ($row = mysql_fetch_array($sql_events)) { $LeadID = $row['ID']; $Industry = $row['Industry']; $Location = $row['Location']; /* Now we do this small line which is basically going to tell PHP to alternate the colors between the two colors we defined above. */ $row_color = ($row_count % 2) ? $color1 : $color2; // Echo your table row and table data that you want to be looped over and over here. echo '<tr> <td width="110" bgcolor="'.$row_color.'" nowrap>'.$LeadID.'</td> <td bgcolor="'.$row_color.'"> <a>'.$Industry.'</a></td> <td bgcolor="'.$row_color.'"> <a>'.$Location.'</a></td> </tr>'; // Add 1 to the row count $row_count++; } // Close out your table. echo '</table>'; mysql_close($db); ?> Quote Link to comment Share on other sites More sharing options...
peterbarone Posted March 5, 2007 Share Posted March 5, 2007 See if this works for you. echo '<table><thead><th width="110" style="background-image: url($row_color)" nowrap><p align="center">'; echo "<a href='userpro.php?id="; echo $row['id']; echo "'>"; echo $row['username']; echo "</a></th>"; echo '<th style="background-image: url($row_color)">'; if($_SESSION['level'] == "2") { echo $row['email']; } else {if($row['show_email'] == "1") { echo $row['email']; } else { echo "hidden"; }} echo "</th>"; echo '<th style="background-image: url($row_color)">'; echo $row['urank']; echo "</th>"; echo '<th style="background-image: url($row_color)">'; echo $row['last_login']; echo "</th></thead>"; // Add 1 to the row count $row_count++; } // Close out your table. echo "</table>"; Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 5, 2007 Author Share Posted March 5, 2007 Try this below <? echo '<table width="100%" border="0" cellpadding="4" cellspacing="0"> <tr> <td width="110"><b>Lead Id</b></td> <td width="110"><b>Industry</b></td> <td><b>Location</b></td> </tr>'; // Define your colors for the alternating rows $color1 = "#CCFFCC"; $color2 = "#CCFF99"; $row_count = 0; // Perform an statndard SQL query: $sql_events = mysql_query("SELECT * FROM _Leads WHERE LINKID = '$userid'") or die(mysql_error()); // We are going to use the "$row" method for this query. This is just my preference. while ($row = mysql_fetch_array($sql_events)) { $LeadID = $row['ID']; $Industry = $row['Industry']; $Location = $row['Location']; /* Now we do this small line which is basically going to tell PHP to alternate the colors between the two colors we defined above. */ $row_color = ($row_count % 2) ? $color1 : $color2; // Echo your table row and table data that you want to be looped over and over here. echo '<tr> <td width="110" bgcolor="'.$row_color.'" nowrap>'.$LeadID.'</td> <td bgcolor="'.$row_color.'"> <a>'.$Industry.'</a></td> <td bgcolor="'.$row_color.'"> <a>'.$Location.'</a></td> </tr>'; // Add 1 to the row count $row_count++; } // Close out your table. echo '</table>'; mysql_close($db); ?> okay so when i do it your way i get a florescent green color Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 5, 2007 Author Share Posted March 5, 2007 See if this works for you. echo '<table><thead><th width="110" style="background-image: url($row_color)" nowrap><p align="center">'; echo "<a href='userpro.php?id="; echo $row['id']; echo "'>"; echo $row['username']; echo "</a></th>"; echo '<th style="background-image: url($row_color)">'; if($_SESSION['level'] == "2") { echo $row['email']; } else {if($row['show_email'] == "1") { echo $row['email']; } else { echo "hidden"; }} echo "</th>"; echo '<th style="background-image: url($row_color)">'; echo $row['urank']; echo "</th>"; echo '<th style="background-image: url($row_color)">'; echo $row['last_login']; echo "</th></thead>"; // Add 1 to the row count $row_count++; } // Close out your table. echo "</table>"; My table starts up further in the script so i dont need that plus when i did is jacks up my table. and <theader> didnt do much, and it didnt work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.