custimiz output

Discussion in 'PHP' started by johny321, Jan 16, 2011.

  1. #1
    hi
    i am trying to do php i have wrote code(mention below) this gives output like relational table mean heading above then result below the heading.


    <?php
    include('conn.php');
    ?>
    <table align="center" border="1" bordercolor="#000000" width="800">
    <tr>
    <td>
    <table align="center" border=".8" bordercolor="#000000" width="100%">
    <tr bgcolor="#33FF33">
    <th>
    Drug
    </th>
    <th>
    Cyclodextrin
    </th>
    <th>
    Trade Name
    </th>
    <th>
    formulation
    </th>
    <th>
    country
    </th>

    </tr>


    <?php

    if (isset($_GET['act']) and $_GET['act'] == 1)
    {
    $search = $_GET['search'];

    $sql_ser = "SELECT * FROM sp_cyclo_dds WHERE drug LIKE '%".trim($search)."%'"; //'%.$search.%'";
    $result_ser = mysql_query($sql_ser);
    //echo mysql_num_rows($result_ser);
    if (mysql_num_rows($result_ser) > 0)
    {
    while($row = mysql_fetch_array($result_ser))
    {
    echo '
    <tr bgcolor="#CCCCCC" >
    <td>
    '.$row['drug'].'
    </td>
    <td>
    '.$row['cyclodextrin'].'
    </td>
    <td>
    '.$row['trade_name'].'
    </td>
    <td>
    '.$row['formulation'].'
    </td>
    <td>
    '.$row['country'].'
    </td>



    </tr>
    ';
    }
    }
    }


    ?>
    </table>
    </td>
    </tr>
    </table>


    </body>


    first i want to change the color of each row (below the headings, which adopt only one color as it is under in while loop in above case).

    second i want to do that all the results under drug heading (stored in drug attribute of database) should be hyper links for other web pages.and every entry of drug attribute is link to different link on web.

    thanks in advance
     
    johny321, Jan 16, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Place this before 'while

    
       //Set alternate row color
    $dvd_color_ctr = 1;
    
       if ($dvd_color_ctr == 1) { $dvd_row = CCCCCC; $dvd_color_ctr = 2; }
        else { $dvd_row = FFFFFF; $dvd_color_ctr = 1; }
    
    PHP:
    ..and the your <tr bgcolor="#CCCCCC" > becomes

    
    <tr bgcolor="'.$dvd_row.'">
    
    Code (markup):
    I'm not sure about the second part of your question, do you have the links already stored in database ?
     
    MyVodaFone, Jan 16, 2011 IP
  3. johny321

    johny321 Member

    Messages:
    293
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    when i paste your code error results

    Notice: Use of undefined constant CCCCCCC - assumed 'CCCCCCC' in D:\wamp\www\samina\cd_dd_sp_result.php on line 51

    yes i have store links in another table name links.
     
    johny321, Jan 16, 2011 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    The Notice is just saying that I should have put single quotes around the colors 'CCCCCCC' so change those
     
    MyVodaFone, Jan 17, 2011 IP