Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WEB FORUM's 1

Status
Not open for further replies.

TrueJoker

Technical User
Jun 14, 2006
115
GB
I ahve just created a web forum using PHP & MySQL, it is only a basic forum and i am now trying to change to look of it etc.

I have been playing about with some code to try and alternate the colour of the posts as the appear on the screen, say the first will be a pale blue and the next will be a white, then pale blue then white and so on and so forth. I have told to database to create an ID value for each post, and have been trying to use this `ID` value to determine which post should be which colour, i.e. every odd value will be the colour white and every even value will be pale blue.

Unfortunately every attempt has failed. How do i make it recognise an any odd or even number and make it change the background colour of the table to the corresponding colour?
 
the code i was trying and modifying is as follows

i believe the problem may lie with '?!?!?!' at the beginning but knowing me there are many problems with this code or it is just completely useless!

Code:
if (['a_id'] = '?!?!?!') {
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
      <td width="13%" rowspan="2" valign="top" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
      <td width="87%" bgcolor="#F8F7F1" align="right"><? echo $rows['a_datetime']; ?></td>
      </tr>
    <tr>
      <td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
      </tr>
    
  </table>

else

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#5EB9FF">
    <tr>
      <td width="13%" rowspan="2" valign="top" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
      <td width="87%" bgcolor="#F8F7F1" align="right"><? echo $rows['a_datetime']; ?></td>
      </tr>
    <tr>
      <td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
      </tr>
    
  </table>
 
change
Code:
if (['a_id'] = '?!?!?!') {
to
Code:
if (['a_id'] =[red]=[/red] '?!?!?!') {

the '=' is not a comparison operator but an assignment operator
 
should of said i obviouslt am not using the '?!?!?!' in the code but i used it to represent something that i am unsure about what to use. as at this point i want it to determine whether the id value is odd or even and then act corespondingly.
 
the point was to add the second equals sign. obviously the '?!?1?1' is entirely your own affair.

as you have the code the condition will ALWAYS evaluate to true

the better way to do alternating rows is like this

Code:
$style='';
while ($row=mysql_fetch_assoc($result)){
 $style = ($style=='row_even')?'row_odd':'row_even');
 echo "<tr class=\"$style\"><td>some text</td></tr>";
}
and use css to include a style definition for row_odd and row_even.
 
oops even then this
Code:
if (['a_id'] == '?!?!?!') {
will not work as the left side of the comparison is not a variable. I assume it should read
Code:
$row['a_id']
or something similar.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top