runnerjp Posted September 14, 2008 Share Posted September 14, 2008 <?php session_start(); require_once '../settings.php'; $getthreads="Select * from forumtutorial_posts ORDER BY lastrepliedto DESC LIMIT 10"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3[title]=strip_tags($getthreads3[title]); $getthreads3[author]=strip_tags($getthreads3[author]);?> <br> <b> <?php $currentcolor = "#00468C"; echo '<table width="500 border="0" >'; while($row = mysql_fetch_array($getthreads2, MYSQL_ASSOC)) { $currentcolor = ($currentcolor=='#00468C' ? '#000000' : '#00468C'); echo '<tr bgcolor="'. $currentcolor .'"> <td><? echo $getthreads3[title]?> </td> </tr>'; } echo '</table>'; ?> </b> <? } ?> from this all i get is 3 different colour lines :S can be seen here http://www.runningprofiles.com/members/test.php Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/ Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 Change echo '<tr bgcolor="'. $currentcolor ."> <td><? echo $getthreads3[title]?> </td> </tr>'; to echo '<tr bgcolor="'. $currentcolor .'"> <td>'.$getthreads3[title].'</td> </tr>'; Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641118 Share on other sites More sharing options...
runnerjp Posted September 14, 2008 Author Share Posted September 14, 2008 humm i wunder why i php tags in php tags :S... thanks Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641133 Share on other sites More sharing options...
runnerjp Posted September 14, 2008 Author Share Posted September 14, 2008 ok i tested it out and for some reason its only displaying the 1st output but repeating it 2 times :S... still seen on same url Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641135 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 $getthreads3[title] should be $row['title'] Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641137 Share on other sites More sharing options...
runnerjp Posted September 14, 2008 Author Share Posted September 14, 2008 humm but now i have done that its not displaying it like this "Select * from forumtutorial_posts ORDER BY lastrepliedto DESC LIMIT 10"; i can only see 2 outputs and then a blue line :S Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641142 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 Modified your code abit, not sure what you was doing with your first while loop but doesn't seem it was required <?php session_start(); require_once '../settings.php'; $sql = "Select * from forumtutorial_posts ORDER BY lastrepliedto DESC LIMIT 10"; $result = mysql_query($sql) or die("Could not get threads"); echo '<table width="500 border="0" >'; $i = 0; while($row = mysql_fetch_assoc($resul)) { $color = (($i%2 == 0) ? '#000000' : '#00468C'); echo "\n".' <tr bgcolor="'. $color .'"> <td>'.$row['title'].'</td><td>'.$row['author'].'</td> </tr>'; $i++; } echo ' </table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641145 Share on other sites More sharing options...
runnerjp Posted September 14, 2008 Author Share Posted September 14, 2008 thnaks... what does (($i%2 == 0) ? mean? also.. in "Select * from forumtutorial_posts ORDER BY lastrepliedto DESC LIMIT 10"; how would i do it so it only gets the results where lastrepliedto doesnot = 0 ? Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641157 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 thnaks... what does (($i%2 == 0) ? mean? The code above checks to see if the remainder is equal to 0. the modulus operater (%) returns the remainder. also.. in "Select * from forumtutorial_posts ORDER BY lastrepliedto DESC LIMIT 10"; how would i do it so it only gets the results where lastrepliedto doesnot = 0 ? Set a condition in your select statement: $sql = "Select * from forumtutorial_posts WHERE lastrepliedto != 0 ORDER BY lastrepliedto DESC LIMIT 10"; Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641160 Share on other sites More sharing options...
runnerjp Posted September 14, 2008 Author Share Posted September 14, 2008 ahh yes... != didnt know that one... thnaks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641164 Share on other sites More sharing options...
runnerjp Posted September 14, 2008 Author Share Posted September 14, 2008 sorry i have anouther question... been hunting around for how to solve it but cant find it how do i use i link within an echo ?? <?php echo "\n".' <tr bgcolor="'. $color .'"> <td>'<a href="#">.$row['title'].</a>'</td> </tr>';?> Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641184 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 You should all place all HTML within a string. PHP does not understand HTML. echo "\n".' <tr bgcolor="'. $color .'"> <td><a href="#">'.$row['title'].'</a></td> </tr>'; Quote Link to comment https://forums.phpfreaks.com/topic/124177-solved-table-displaying-alernet-codes-php-not-working-s/#findComment-641203 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.