how can i put this data in a data table format

Discussion in 'PHP' started by babyphp, Apr 15, 2008.

  1. #1
    how can i put this data in a data table format

    in this order
    first name, last name,email,address,phone
    and also make them a link to display more information



    </head>

    <body>
    <br>
    <br>
    <h1>Vodacom Customer Relation Management</h1>
    <form method="post" action="<?php $PHP_SELF; ?>">
    <div align="center">
    <input type="text" name="search" size=25 maxlength=25>
    <input type="Submit" name="Submit" value=" customer search">
    </div>
    </form>

    <?php
    //connect to mysql

    $username = "";
    $password = "";
    $database = "";
    $server = "";


    $db_handle = mysql_connect($server, $username, $password);
    $db_found = mysql_select_db($database, $db_handle);

    $search=$_POST["search"];

    $result = mysql_query("SELECT * FROM contacts WHERE firstname LIKE '%$search%'");



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


    $firstname=$row["firstname"];
    $lastname=$row["lastname"];
    $email=$row["email"];
    $phone=$row["phone"];


    echo "$firstname <br> $lastname <br> $email <br> $phone <br>";
    }



    ?>



    </body>
    </html>
     
    babyphp, Apr 15, 2008 IP
  2. JLEville

    JLEville Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use this:

    echo "<table>";
    while($row=mysql_fetch_array($result))
    {


    $firstname=$row["firstname"];
    $lastname=$row["lastname"];
    $email=$row["email"];
    $phone=$row["phone"];


    echo "<tr><td>" . $firstname" . "</td><td>" . $lastname . "</td><td>" . $email . "</td><td>" . $phone . "</td></tr>";
    }
    echo "</table>";


    ?>
     
    JLEville, Apr 15, 2008 IP
  3. babyphp

    babyphp Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i get this error

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'


    $result = mysql_query("SELECT * FROM contacts WHERE firstname LIKE '%$search%' OR lastname LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%'");

    echo "<table>";
    while($row=mysql_fetch_array($result))
    {


    $firstname=$row["firstname"];
    $lastname=$row["lastname"];
    $email=$row["email"];
    $phone=$row["phone"];


    echo "<tr><td>" . $firstname" . "</td><td>" . $lastname . "</td><td>" . $email . "</td><td>" . $phone . "</td></tr>";
    }
    echo "</table>";


    ?>
     
    babyphp, Apr 15, 2008 IP
  4. JLEville

    JLEville Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry, i made a typo here:
    echo "<tr><td>" . $firstname" . "</td><td>" . $lastname . "</td><td>" . $email . "</td><td>" . $phone . "</td></tr>";


    change that entire line to:
    echo "<tr><td>" . $firstname . "</td><td>" . $lastname . "</td><td>" . $email . "</td><td>" . $phone . "</td></tr>";
     
    JLEville, Apr 15, 2008 IP