Results 1 to 2 of 2

Thread: what is wrong with this php code?

  1. #1
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    3

    Unhappy what is wrong with this php code?

    Hi;
    I am trying to make an alternate row color for Repeated region of my database driven page,
    I use Dreamweaver mx uisng PHP/mysql with ADODB db connection.
    I know some about php, a newbie you can say.
    this is the php code I got for Alternate row color:

    -----------------------

    <?php $counter = 0; ?>

    DMX Repeat Region Start

    <?php $counter++; ?>
    <?php
    if(($counter % 2) == 0){
    $color = "#FFFFCC";
    }else{ $color = "#FFFFFF";
    }
    ?>
    <tr bgcolor = "<?php echo $color; ?>">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>

    DMX Repeat Region End

    I am not sure if this code works
    ----------------------------------
    I have applied the code to my page but I keep getting an error and I can not find out what is wrong,
    on line 185 is nothing, and the error says there is something wrong on line 185, my last code is ( <?php
    $Rs_Master->Close();
    ?>) and my last code is on line 181 and there is nothing after that, when i take off the code the page works fine but as soon as I add the code I get this error:

    Parse error: parse error,unexpected $end in
    c:\inetpub\wwwroot\testpage\myp_rmdxlcebp5.php on line 185


    and here is all the code with alternative row color applied to it.
    your help is appreciated.

    <?php
    //Connection statement
    require_once('Connections/conn_Ama.php');

    // begin Recordset
    $maxRows_Rs_Master = 10;
    $pageNum_Rs_Master = 0;
    if (isset($HTTP_GET_VARS['pageNum_Rs_Master'])) {
    $pageNum_Rs_Master = $HTTP_GET_VARS['pageNum_Rs_Master'];
    }
    $startRow_Rs_Master = $pageNum_Rs_Master * $maxRows_Rs_Master;
    $colname__Rs_Master = '1';
    if (isset($HTTP_POST_VARS['compMenu'])) {
    $colname__Rs_Master = $HTTP_POST_VARS['compMenu'];
    }
    $query_Rs_Master = sprintf("SELECT c_id, comapny_name, job_title FROM company WHERE comapny_name = '%s'", $colname__Rs_Master);
    $Rs_Master = $conn_Ama->SelectLimit($query_Rs_Master, $maxRows_Rs_Master, $startRow_Rs_Master) or die($conn_Ama->ErrorMsg());
    if (isset($HTTP_GET_VARS['totalRows_Rs_Master'])) {
    $totalRows_Rs_Master = $HTTP_GET_VARS['totalRows_Rs_Master'];
    } else {
    $all_Rs_Master = $conn_Ama->SelectLimit($query_Rs_Master) or die($conn_Ama->ErrorMsg());
    $totalRows_Rs_Master = $all_Rs_Master->RecordCount();
    }
    $totalPages_Rs_Master = (int)(($totalRows_Rs_Master-1)/$maxRows_Rs_Master);
    // end Recordset
    //PHP ADODB document - made with PHAkt 2.2.0?>
    <html>
    <head><title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <table width="740" border="0" cellpadding="0" cellspacing="0">
    <!--DWLayoutDefaultTable-->
    <tr>
    <td width="71" height="68">&nbsp;</td>
    <td width="646">&nbsp;</td>
    <td width="23">&nbsp;</td>
    </tr>
    <tr>
    <td height="28">&nbsp;</td>
    <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->

    // here is the code for Alternate Row color

    <?php
    $counter=0; ?>
    <?php
    $counter++; ?>
    <?php
    if (( $counter %2)==0)
    {
    $color="#ffffcc";
    }
    else{
    $color="#ffffff";
    ?>
    <?php
    while (!$Rs_Master->EOF) {
    ?>

    <tr bgcolor = " <?php echo $color;?>">
    <td width="321" height="28" valign="top"><?php echo $Rs_Master->Fields('comapny_name'); ?></td>
    <td width="325" valign="top"><?php echo $Rs_Master->Fields('job_title'); ?></td>
    </tr>
    <?php
    $Rs_Master->MoveNext();
    }
    ?>
    </table>
    </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="59">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    $Rs_Master->Close();
    ?>

    Thans for your help

  2. #2
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    Hi manou

    Could the problem be:

    PHP Code:
    //PHP ADODB document - made with PHAkt 2.2.0?> 
    The close ?> should be on another line - at the moment it's commented out by the comment.

    The code is also quite messy - you should try avoid combining the HTML and PHP as much as possible. Keep the PHP separate and generate the variables, which are then used inside the HTML. Makes things much easier to debug! Also, the PHP can be inside one set of <?php ?> tags, not numerous as you have now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •