943,754 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 782
  • PHP RSS
Mar 3rd, 2008
0

3 lines of code not working

Expand Post »
php Syntax (Toggle Plain Text)
  1. <table align="left" style="width: 764px">
  2. <tr>
  3. <td>
  4. <?php
  5. $con =mysql_connect("localhost","root","");
  6. mysql_select_db("administration",$con);
  7.  
  8. $list=mysql_query("SELECT * FROM cycles");
  9. echo "<table border=1>";
  10. echo "<tr>" ;
  11. echo "<td align=center style='color:red'>CID</td>";
  12. echo "<td align=center style='color:green'>Brand</td>";
  13. echo "<td align=center style='color:red'>Type</td>";
  14. echo "<td align=center style='color:green'>Style</td>";
  15. echo "<td align=center style='color:red'>Model</td>";
  16. echo "<td align=center style='color:green'>Gear No</td>";
  17. echo "<td align=center style='color:red'>Frame</td>";
  18. echo "<td align=center style='color:green'>Group Set</td>";
  19. echo "<td align=center style='color:red'>Price</td>";
  20. echo "<td align=center style='color:green'>Release Date</td>";
  21. echo "</tr>";
  22.  
  23. $bg = '#eeeeee'; // Set the background color.
  24. while($row=mysql_fetch_array($list))
  25. {
  26. $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
  27. echo "<tr>" ;
  28. echo "<td align=center>".$row['cycleID'] ."</td>";
  29. echo "<td align=center>".$row['brand']."</td>";
  30. echo "<td align=center>".$row['type']."</td>";
  31. echo "<td align=center>".$row['style']."</td>";
  32. echo "<td align=center>".$row['model'] ."</td>";
  33. echo "<td align=center>".$row['gearNo']."</td>";
  34. echo "<td align=center>".$row['frame']."</td>";
  35. echo "<td align=center>".$row['groupSet']."</td>";
  36. echo "<td align=center>".$row['price']."</td>";
  37. echo "<td align=center>".$row['releaseDate']."</td>";
  38. echo "</tr>";
  39. }
  40. echo "</table>";
  41. ?>
  42. </td>
  43. </tr>
  44. </table>

The code from line 23 - 26 is not functioning. Please help.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster
lordx78 is offline Offline
180 posts
since Oct 2007
Mar 3rd, 2008
0

Re: 3 lines of code not working

Hi, is the database throwing an exception? Does the code reach the closing table tag on line 40? Have you tried a record count to see if your row variable contains rows? try echoing the row count - otherwise the code looks fine.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
coffeepot! is offline Offline
11 posts
since Feb 2008
Mar 3rd, 2008
0

Re: 3 lines of code not working

first of all ... where do you use $bg ? i don't see something like
echo "<td bgcolor='".$bg."'> .. if your rows are all white (or #eeeeee) this might be the problem.
Reputation Points: 10
Solved Threads: 15
Junior Poster in Training
silviuks is offline Offline
95 posts
since Apr 2006
Mar 4th, 2008
0

Re: 3 lines of code not working

Click to Expand / Collapse  Quote originally posted by silviuks ...
first of all ... where do you use $bg ? i don't see something like
echo "<td bgcolor='".$bg."'> .. if your rows are all white (or #eeeeee) this might be the problem.
I think silviuks, is right, you not using $bg as background color (you just set its value).
Reputation Points: 10
Solved Threads: 10
Junior Poster in Training
rudevils is offline Offline
80 posts
since Jan 2008
Mar 4th, 2008
0

Re: 3 lines of code not working

I want to alternate the bg colours, row by row, any suggestion.
Reputation Points: 10
Solved Threads: 2
Junior Poster
lordx78 is offline Offline
180 posts
since Oct 2007
Mar 4th, 2008
0

Re: 3 lines of code not working

Quote ...
<?php
@ $rpp; //Records Per Page
@ $cps; //Current Page Starting row number
@ $lps; //Last Page Starting row number
@ $a; //will be used to print the starting row number that is shown in the page
@ $b; //will be used to print the ending row number that is shown in the page


$q="Select SQL_CALC_FOUND_ROWS * from tablename";
$rs=mysql_query($q) or die(mysql_error());
$nr = mysql_num_rows($rs); //Number of rows found with LIMIT in actiong r

$q0="Select FOUND_ROWS()";
$rs0=mysql_query($q0) or die(mysql_error());
$row0=mysql_fetch_array($rs0);
$nr0 = $row0["FOUND_ROWS()"];
$i=$nr0;
while ($line=mysql_fetch_array($rs))
{
if($i %2 == 0)
{
echo "<tr>";
echo "<td>";
echo "<table bgcolor='#fefefe' width='73%' align='center' border='0'>";
echo "<tr><td width='25%'></td></tr>";
echo "</table>";
echo "</td>";
echo "</tr>";


}
else if($i %2 == 1)
{
echo "<tr>";
echo "<td>";
echo "<table bgcolor='#e5e1e1' width='73%' border='0' align='center'>";
echo "<tr><td width='55%'></td></tr>";
echo "</table>";
echo "</td>";
echo "</tr>";

}
$i--;
}
}
hope this works
Reputation Points: 3
Solved Threads: 2
Junior Poster
kings is offline Offline
107 posts
since Nov 2007
Mar 4th, 2008
0

Re: 3 lines of code not working

echo "<tr bgcolor=$bg>"; instead of echo "<tr>";
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 4th, 2008
0

Re: 3 lines of code not working

Thanks guys, it solved.
Reputation Points: 10
Solved Threads: 2
Junior Poster
lordx78 is offline Offline
180 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: hyperlink and upload in PHP
Next Thread in PHP Forum Timeline: img not displayed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC