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>
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>"; ?>
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>"; ?>
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>";