SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Alternating Table Rows

    I have had a go at creating some alternating table rows but the code runs correctly but just doesn't provide the alternating rows. I have looked through various tutorials and can't find an answer. So i was hoping someone on here might be able to help me


    Code:
    <?php
    
    require_once('databaseconnection.php'); 
    
    $keywordentered = $_GET['keyword']; 
    
    echo '<table class="table">';
    echo '<tr><th>Order Number</th><th>Part Number</th><th>Part Description</th><th>Order Quantity</th><th>Order Date</th><th>Customer Order Number</th><th>Originally Sold To</th><th>Contact Info</th></tr>';
     
    $color1 = "#00E639"; 
    $color2 = "#0039E6"; 
    $row_count = 0;
      
    switch($_GET['type']) {
      case 'ordernumber':
      if ($_GET['contains']) {
         $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Order_No LIKE '".$keywordentered."%' ORDER BY Order_No ASC"); }
    	 else {
    	 $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Order_No LIKE '$keywordentered'" ); }
        break;
      case 'partnumber':
       if ($_GET['contains']) {
         $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Part_No LIKE '".$keywordentered."%' ORDER BY Part_No ASC"); }
    	 else {
    	 $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Part_No LIKE '$keywordentered'"); } 
        break;
      case 'accountname':
        if ($_GET['contains']) {
         $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Account_Name LIKE '".$keywordentered."%' ORDER BY Account_Name ASC"); }
    	 else
    	 $result = odbc_exec($odbc, "SELECT * FROM orderpartnumbertable WHERE Account_Name LIKE '$keywordentered'" ); 
        break;
    }
    
    
    while (($row = odbc_fetch_array($result)) !== false) {
    $row_color = ($row_count % 2) ? $color1 : $color2;
    echo '<tr bgcolor="$row_color">';
    echo '<td>' . $row['Order_No'] . '</td>';
    echo '<td >' . $row['Part_No'] . '</td>';
    echo '<td>' . $row['Part_Description'] . '</td>';
    echo '<td>' . $row['Order_Qty'] . '</td>';
    $string = $row['Order_Date'] ;
    $date =  $string{6} . "" . $string{7} . "/" . $string{4} . $string{5} . "/" . $string{0} . $string{1} . $string{2} . $string{3} ;
    echo '<td>' . $date . '</td>';
    echo '<td>' . $row['Customer_Order_No'] . '</td>';
    echo '<td>' . $row['Account_Name'] . '</td>';
    echo '<td><a href="ordersearchdetails.php?fnp_site=' . rawurlencode($row['FNP_Site']) . '& Record_ID='. rawurlencode($row['Record_ID']) . '" class="emaillink">More Info</a>' . '</td>'; 
    echo '</tr>';
    $row_count ++;
    
    }
    echo '</table>'; 
    
    ?>

    Thank You

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean alternating row's color? If so do it like this:
    PHP Code:
    echo '<tr bgcolor="' $row_color '">'
    And this line:
    PHP Code:
    $row_color = ($row_color == $color2) ? $color1 $color2
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are enclosing your variable inside single quotes. You need to use double quotes if you want your strings to parse variables. I would also use CSS to style the rows.
    PHP Code:
    echo '<tr style="background-color: ' $row_color '">'
    Or even better:
    Code CSS:
    .even
    {
        background-color: #0039E6;
    }
     
    .odd
    {
        background-color: #00E639;
    }
    PHP Code:
    $class_name = ($row_count 2) ? "odd" "even";
    echo 
    '<tr class="' $class_name '">'

  4. #4
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers that works perfectly now. Thank you for the help


Bookmarks

Posting Permissions

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