faqts : Computers : Databases : MySQL : Language and Syntax : Queries : Where

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 21 people (29%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How to display a record in a table by simply giving the record number in the where clause, where record number will not be the field?.

Dec 7th, 2000 10:00
Narendra Jain, Naveen Ghanathe,


You can use the query like:
select emp_name, emp_contact from employees 
where emp_id = $emp_id;
This way you do not use the emp_id in the result set. Only name and
contact are returned from the query.
Example below:
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$qry = "select emp_name, emp_contact from employees ",
       "where emp_id = ", $emp_id
$result = mysql_query($qry,$db);
if ($myrow = mysql_fetch_array($result)) {
    echo "<table border=1>\n";
    echo "<tr><td>Name</td><td>Contact</td></tr>\n";
    do {
        printf("<tr><td>%s </td><td>%s</tr>\n", 
               $myrow["emp_name"],
               $myrow["emp_contact"]);
       } 
    while ($myrow = mysql_fetch_array($result));
    echo "</table>\n";
} else {
   echo "Sorry, no records were found for ", $emp_id;   
}
?>