Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

[RESOLVED] Alternating row colours PHP & MySQL

  • 12-05-2005 10:44am
    #1
    Closed Accounts Posts: 546 ✭✭✭


    Hi.

    I've got a database with 8 fields & 50 odd rows of data. I need to display the data is a readable format. I can connect to my database etc no problem and display the data. The problem arises when I try to alternate the colour of the rows. I'm following this BioRUST Turorial.

    My code is split into two files, the first one is config.php and the second one is index_new.php.

    Here's the code for config.php:
    [PHP]<?PHP
    mysql_connect('server','username','password') or die(mysql_error());
    mysql_select_db('projects');
    }

    function processRow($count)
    {
    switch($count){
    case 1:
    $color = '#CCCCCC';
    break;
    case 2:
    $color = '#B9B9B9';
    break;
    case 3:
    $color = '#7F7F7F';
    break;
    default:
    $color = '#FFFFFF';
    }
    return $color;
    }
    ?>[/PHP]


    Here's my code for index_new.php:
    [PHP]<?PHP

    //include the config file
    include 'config.php';

    //Start the table
    echo '<table width="580" cellspacing="0" cellpadding="2" class="displaytable">';

    //Run the query to get the data from the table
    $query = mysql_query('SELECT * FROM Prj_Status ORDER BY ID ASC') or die('There was an error!');

    while( $row = mysql_fetch_array ( $query ) ) {

    //Assign the columns in our tabe to variables
    $id=$row["ID"];
    $prj=$row["Prj"];
    $prj_name=$row["Prj_Name"];
    $status=$row["Status"];
    $comments=$row["Prj_Comments"];
    $comp=$row["Comp"];
    $sent=$row["Sent"];
    $draft=$row["Draft"];

    //start the alternating colour bit
    $count = $count + 1;

    echo '
    <tr class="columns" >
    <td class="cells" width="30" bgcolor="'.echo processRow($count).'">'.$id'</td>
    <td class="cells" width="70" bgcolor="'.echo processRow($count).'">'$prj'</td>
    <td class="cells" width="200" bgcolor="'.echo processRow($count).'">'$prj_name'</td>
    <td class="cells" width="20" bgcolor="'.echo processRow($count).'">' $status'</td>
    <td class="cells" width="200" bgcolor="'.echo processRow($count).'">'$comments'</td>
    <td class="cells" width="20" bgcolor="'.echo processRow($count).'">'$comp'</td>
    <td class="cells" width="20" bgcolor="'.echo processRow($count).'">'$sent'</td>
    <td class="cells" width="20" bgcolor="'.echo processRow($count).'">'$draft'</td>
    </tr>'
    ;
    if($count == 3){
    $count = 0;
    }
    }
    echo '</table>'

    ?>[/PHP]

    But I am getting this error:
    Parse error: parse error, unexpected T_ECHO in /hsphere/local/home/wpi/domain/secure/index_new.php on line 39

    Line 39 is: [PHP]<td class="cells" width="30" bgcolor="'.echo processRow($count).'">'.$id'</td>[/PHP]


    Any help would be great.

    Thanks! :D


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    try using this
    echo '
    <tr class="columns" >
        <td class="cells" width="30" bgcolor="'.processRow($count).'">'.$id.'</td>
        <td class="cells"  width="70" bgcolor="'.processRow($count).'">'.$prj.'</td>
        <td class="cells"  width="200" bgcolor="'.processRow($count).'">'.$prj_name.'</td>
        <td class="cells"  width="20" bgcolor="'.processRow($count).'">'.$status.'</td>
        <td class="cells"  width="200" bgcolor="'.processRow($count).'">'.$comments.'</td>
        <td class="cells"  width="20" bgcolor="'.processRow($count).'">'.$comp.'</td>
        <td class="cells"  width="20" bgcolor="'.processRow($count).'">'.$sent.'</td>
        <td class="cells"  width="20" bgcolor="'.processRow($count).'">'.$draft.'</td>
    </tr>' 
    


  • Closed Accounts Posts: 546 ✭✭✭exactiv


    Worked a treat.

    Thanks a million! :D


Advertisement