Jump to content

[SOLVED] table displaying alernet codes... php not working :S


runnerjp

Recommended Posts

<?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

Change

    echo '<tr bgcolor="'. $currentcolor .">
                <td><? echo $getthreads3[title]?> </td>
            </tr>';

to

    echo '<tr bgcolor="'. $currentcolor .'">
                <td>'.$getthreads3[title].'</td>
            </tr>';

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>';

?>

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";

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>';?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.