lukekelly Posted June 18, 2009 Share Posted June 18, 2009 Hi All, I have a small styling issue i need help with. in the script below i would like every other row to be coloured. <style type="text/css"> .ay_client { border:2px solid #ccc; background:#ff; width:500px; padding:10px; text-align:center; overflow:auto; table-cell:2px solid #ccc; } td { position: relative; width: 14%; margin: 0; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #000; padding-top: 1em; vertical-align: center; } </style> <div class="ay_client"> <?php $query = mysql_query("SELECT * FROM jos_ay_client_activity"); { echo $row['month']; } echo "<table><tr><td><b>Date Time</b></td> <td><b>Month</b></td> <td><b>Year</b></td> <td><b>Client</b></td> <td><b>Surveys</b></td> <td><b>Air Tests</b></td> <td><b>Project Managements</b></td> <td><b>Bulk Samples</b></td></tr>"; while($row = mysql_fetch_array($query)) { echo "<tr><td>"; echo $row['datetime']; echo "</td><td>"; echo $row['month']; echo "</td><td>"; echo $row['year']; echo "</td><td>"; echo $row['client']; echo "</td><td>"; echo $row['surveys']; echo "</td><td>"; echo $row['airtests']; echo "</td><td>"; echo $row['project']; echo "</td><td>"; echo $row['bulks']; echo "</td></tr>"; } echo "</table>"; ?></div> I have found some solutions, but ofc im getting errors because of the php elements... any suggestions? Thanks in advance Luke Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/ Share on other sites More sharing options...
trq Posted June 18, 2009 Share Posted June 18, 2009 And these error you speak of are.... ? Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858802 Share on other sites More sharing options...
lukekelly Posted June 18, 2009 Author Share Posted June 18, 2009 Well as i said there were a few solutions (which i have since taken out of the code - because they did not work) the "solutions" i found were to... <style type="text/css"> .highlightoff{ background-color:white; } .highlighton{ background-color: yellow; } </style> Then this in every td tag: class="highlightoff" onmouseover="this.className='highlighton'" onmouseout="this.className='highlightoff'" That would highlight the cells when hovered over - not what i desired but it would suit. This however seems nearer the solution: $row = 25; $x = 1; while ($x <= $row) { if($x%2): $color = "#FFFFFF"; else: $color = "#CCCCCC"; endif; print "<tr><td style=\"background-color: ".$color."\">row #".$x."</td></tr>\n"; $x++; } But again cant seem to get it to work. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858817 Share on other sites More sharing options...
Jibberish Posted June 18, 2009 Share Posted June 18, 2009 this is what I normaly do for this. tr.odd { background-color:#ffffff; } tr.even { background-color:#dff3f7; } <?php echo '<table>'; for ($i = 0; $i < 10; $i++) { $class - $i%2 = 0? 'odd':'even'; echo '<tr class="' . $class . '" ><td>hello</td></tr>'; } echo '</table>'; ?> Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858836 Share on other sites More sharing options...
lukekelly Posted June 18, 2009 Author Share Posted June 18, 2009 Thanks for that, although im getting an error on the line $class - $i%2 = 0? 'odd':'even'; Parse error: syntax error, unexpected '=' Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858847 Share on other sites More sharing options...
Jibberish Posted June 18, 2009 Share Posted June 18, 2009 Thanks for that, although im getting an error on the line $class - $i%2 = 0? 'odd':'even'; Parse error: syntax error, unexpected '=' sorry its ment to be $class = $i%2 == 0? 'odd':'even'; Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858858 Share on other sites More sharing options...
lukekelly Posted June 18, 2009 Author Share Posted June 18, 2009 sorry its ment to be $class = $i%2 == 0? 'odd':'even'; Ok great now getting results on the page, however its not styling them as i test i just used your code: <style type="text/css"> tr.odd { background-color:#ffffff; } tr.even { background-color:#CCCCCC; } </style> <?php echo '<table>'; for ($i = 0; $i < 10; $i++) { $class - $i%2 == 0? 'odd':'even'; echo '<tr class="' . $class . '" ><td>hello</td></tr>'; } echo '</table>'; ?> I get hello 10 times w/o any formatting/styling somthing with for ($i = 0; $i < 10; $i++) { ? seems if i change the variable < 10 to say 5 it will display 5 Hello's! Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858888 Share on other sites More sharing options...
Jibberish Posted June 18, 2009 Share Posted June 18, 2009 its because you still have $class - $i%2 == 0? 'odd':'even'; when it needs to be $class = $i%2 == 0? 'odd':'even'; Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858895 Share on other sites More sharing options...
lukekelly Posted June 18, 2009 Author Share Posted June 18, 2009 Sorry about that, i noticed the extra = but not the - to = , thanks for your help with that jibberish, going to merge the two together now! Kudos to you Luke Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858898 Share on other sites More sharing options...
lukekelly Posted June 18, 2009 Author Share Posted June 18, 2009 Ok just a problem putting it together with my existing code Here is how i've implemented it so far: <style type="text/css"> .ay_client { border:2px solid #ccc; background:#ff; width:500px; padding:10px; text-align:center; overflow:auto; table-cell:2px solid #ccc; } td { position: relative; width: 14%; margin: 0; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #000; padding-top: 1em; vertical-align: center; } tr.odd { background-color:#ffffff; } tr.even { background-color:#CCCCCC; } </style> <div class="ay_client"> <?php $query = mysql_query("SELECT * FROM jos_ay_client_activity"); { echo $row['month']; } echo '<table><tr><td><b>Date Time</b></td> <td><b>Month</b></td> <td><b>Year</b></td> <td><b>Client</b></td> <td><b>Surveys</b></td> <td><b>Air Tests</b></td> <td><b>Project Managements</b></td> <td><b>Bulk Samples</b></td></tr></table>'; while($row = mysql_fetch_array($query)) echo '<table>; for ($i = 0; $i < 10; $i++) { $class = $i%2 == 0? 'odd':'even'; echo "<tr class="' . $class . '" ><td>"; echo $row['datetime']; echo "</td><td>"; echo $row['month']; echo "</td><td>"; echo $row['year']; echo "</td><td>"; echo $row['client']; echo "</td><td>"; echo $row['surveys']; echo "</td><td>"; echo $row['airtests']; echo "</td><td>"; echo $row['project']; echo "</td><td>"; echo $row['bulks']; echo "</td></tr>"; } echo "</table>'"; ?></div> Im getting - Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' eval()'d code on line 41 41 is $class = $i%2 == 0? 'odd':'even'; I cant make out what it is wanting, i added another ; on the end; which ofc wasn't right... anyone see anything that clearly stands out as being obvious? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-858973 Share on other sites More sharing options...
J.Daniels Posted June 18, 2009 Share Posted June 18, 2009 You are missing a closing quote: echo '<table>'; Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-859049 Share on other sites More sharing options...
lukekelly Posted June 19, 2009 Author Share Posted June 19, 2009 Hey thanks for your reply, unfortunately that was not the problem solved, a step further this time but im getting an error on the row below now echo "<tr class="' . $class . '" ><td>"; Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' eval()'d code on line 42. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-859446 Share on other sites More sharing options...
Dathremar Posted June 19, 2009 Share Posted June 19, 2009 echo "<tr class='" . $class . "' ><td>"; Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-859452 Share on other sites More sharing options...
lukekelly Posted June 19, 2009 Author Share Posted June 19, 2009 Thanks Dathremar, the error threw me! Im not getting any data up now but at least im no longer getting any errors. Ill post back if/when i have it 100% sorted ill then contribute the code to snippets. Thanks Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-859461 Share on other sites More sharing options...
lukekelly Posted June 22, 2009 Author Share Posted June 22, 2009 Ok so i am no getting results with <style type="text/css"> .ay_client { border:2px solid #ccc; background:#fff; width:500px; padding:10px; text-align:center; overflow:auto; table-cell:2px solid #ccc; } td { position: relative; width: 14%; margin: 0; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #000; padding-top: 1em; vertical-align: center; } tr.odd { background-color:#ffffff; } tr.even { background-color:#cccccc; } </style> <div class="ay_client"> <?php $query = mysql_query("SELECT * FROM jos_ay_client_activity"); { echo $row['month']; } ?><table><tr><td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=datetime&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=datetime&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Entered</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=month&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=month&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Month</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=year&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=year&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Year</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=client&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=client&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Client</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=surveys&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=surveys&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Surveys</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=airtests&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=airtests&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Air Tests</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=project&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=project&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Projects</b></td> <td><b> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=bulks&dir=ASC"> <img src="images/M_images/sort0.png"></a> <a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=bulks&dir=DESC"> <img src="images/M_images/sort1.png"></a> <br>Bulks</b></td></tr></table> <?php while($row = mysql_fetch_array($query)) { echo '<table>'; for ($i = 0; $i < 10; $i++) { $class = $i%2 == 0? 'odd':'even'; echo "<tr class='" . $class . "' ><td>"; echo $row['datetime']; echo "</td><td>"; echo $row['month']; echo "</td><td>"; echo $row['year']; echo "</td><td>"; echo $row['client']; echo "</td><td>"; echo $row['surveys']; echo "</td><td>"; echo $row['airtests']; echo "</td><td>"; echo $row['project']; echo "</td><td>"; echo $row['bulks']; echo "</td></tr>"; } echo "</table>"; } ?></div> Only problem is i'm getting each result returned 10 times! If for ($i = 0; $i < 10; $i++) Is changed to for ($i = 0; $i < 1; $i++) I get correct results but no formatting... Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-861103 Share on other sites More sharing options...
gizmola Posted June 22, 2009 Share Posted June 22, 2009 you don't need a for loop, just a variable you increment each time you fetch a row. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-861106 Share on other sites More sharing options...
lukekelly Posted June 22, 2009 Author Share Posted June 22, 2009 Ok thanks, i'm not familiar with what i would need to put in as a variable; ill have a look around.. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-861137 Share on other sites More sharing options...
lukekelly Posted June 23, 2009 Author Share Posted June 23, 2009 Ive been unable to find a solution to my problem, could some one point me in the right direction please? thanks Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-861887 Share on other sites More sharing options...
J.Daniels Posted June 23, 2009 Share Posted June 23, 2009 Take out the for loop and add a counter: <?php $count = 0; while($row = mysql_fetch_array($query)) { echo '<table>'; $class = $count%2 == 0? 'odd':'even'; echo "<tr class='" . $class . "' ><td>"; echo $row['datetime']; echo "</td><td>"; echo $row['month']; echo "</td><td>"; echo $row['year']; echo "</td><td>"; echo $row['client']; echo "</td><td>"; echo $row['surveys']; echo "</td><td>"; echo $row['airtests']; echo "</td><td>"; echo $row['project']; echo "</td><td>"; echo $row['bulks']; echo "</td></tr>"; echo "</table>"; $count++; } Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-862029 Share on other sites More sharing options...
gizmola Posted June 23, 2009 Share Posted June 23, 2009 One little tweak to j.Daniels code: $count = 0; echo '</pre> <table>'; while($row = mysql_fetch_array($query)) { $class = $count%2 == 0 ? 'odd' : 'even'; echo ""; echo $row['datetime']; echo ""; echo $row['month']; echo ""; echo $row['year']; echo ""; echo $row['client']; echo ""; echo $row['surveys']; echo ""; echo $row['airtests']; echo ""; echo $row['project']; echo ""; echo $row['bulks']; echo ""; $count++; } echo "</table> Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-862252 Share on other sites More sharing options...
lukekelly Posted June 24, 2009 Author Share Posted June 24, 2009 Thanks a lot for your replys guys - thats done the job nicely - i will now compare the two codes to see what you have changed so i can learn from this and for everyone's benefit: Added in the counter: $count = 0; $count++; Changed: $class = $i%2 == 0? 'odd':'even'; to $class = $count%2 == 0 ? 'odd' : 'even'; Now that its sorted i can logically see the problem was the line with $i affecting the result outcome. After that the code was tidied up. However I'm still not 100% sure when you use a loop so i will read up on that But once again thanks for your help, has been insightful and prompt. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-862702 Share on other sites More sharing options...
gizmola Posted June 24, 2009 Share Posted June 24, 2009 Just to clarify, you already had a loop -- which was the mysql_fetch_array() loop. When you do a a query you get a result SET. That set could be anything from no rows, to the size of your tables. Each time that line returns true, a row gets fetched, and the variable gets incremented. So the other thing I changes was moving the table definition outside the loop, because initially it was making a table every time a row was fetched, and I inferred that what you really wanted was one table, and to make a new table row for each row fetched from the result set. The simple modulus 2 function of course gives you the functionality to alternate the style name. So to clarify, you have a loop and a variable being incremented every time the loop runs. Your initial mistake was that even though you arleady had the while() loop, which runs until the result set is finished, you were unclear I guess that you already had what you needed, so you stuck in a for() loop, which was not what you wanted, as you already had the loop you needed. HTH. Link to comment https://forums.phpfreaks.com/topic/162739-solved-styling-issue/#findComment-862938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.