0

hi everyone :)
i know how to show all the records from database in an html table but how would i show specific category.for example i want to show records only with type T (type T is in database).im new with php and i dont know how to do it properly.thankyou here is my code

<?php include("../includes/config.php"); ?>
<!DOCTYPE HTML>
<html>
<head>
<title>Admdin Home</title>
<link rel="StyleSheet" href="css/style.css" type="text/css" media="screen">
</head>
<body>
<?php include("includes/header.php"); ?>
<?php include("includes/nav.php"); ?>
<?php include("includes/aside.php"); ?>
<div id="maincontent">

    <div id="breadcrumbs">
        <a href="">Home</a> >
        <a href="">Manage Users</a> >
        List Users
    </div>
    <h2>Teachers List</h2>
</div>
<?php
 if ($_SESSION["isadmin"])
   {

   $con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con)
    {
   die('Could not connect: ' . mysql_error());

    }



mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM accounts WHERE (type=='T')");
echo "<table border='1'>
<tr>
<th>E-mail</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Type</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
    echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['type'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

</body>
<?php include("includes/footer.php"); ?>
</html>
<?php
    }
    else
    {
        header("Location: ".$fullpath."login/unauthorized.php");

    }
?>
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Riu 2009
1

In MySQL queries, you only use one = char to compare values, not two.

SELECT ... WHERE type = 'T'

Also, you should always check database results before trying to use them. That way, errors like the one above will be much easier to debug. For example:

$sql = "SELECT invalid query";
$result = mysql_query($sql);
if (!$result) {
    trigger_error("MySQL query failed: " . mysql_error(), E_USER_ERROR);
}

And, while I'm already at it, the mysql_query family of functions - the old MySQL API extension - is deprecated and really shouldn't be used. Instead use PDO or MySQLi.

Edited by Atli

0

thankyou very much for the additional info thts really helpful thanks again :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.