Check if ID number is available
Ok? here?s the code for a ?view.php? page, I wrote this script to view the results of students when they type in their ID Number.
PHP:<?php
// Connect to databse
$db = mysql_connect("localhost", "root", "password here");
mysql_select_db("12",$db);
// Start Query
$query = "SELECT Idnumber, Name, Year, Grade FROM re WHERE idnumber='$id'";
$result = mysql_query($query) or die(mysql_error());<br>
//show table header
echo "<table border=3 width=50% bordercolor=#000066>";
echo"<tr>
<td align=center bgcolor=#00FFFF><b>Id Number</b></td>
<td align=center bgcolor=#00FFFF><b>Student's Name</b></td>
<td align=center bgcolor=#00FFFF><b>Year</b></td>
<td align=center bgcolor=#00FFFF><b>Grade</b></td>
</tr>";
// Show Data
if ($row = mysql_fetch_array($result))
{
echo "<TR><TD align=center bgcolor=#66CCFF>";
echo $row["Idnumber"];
echo "<TD align=center bgcolor=#66CCFF>";
echo $row["Name"];
echo "<TD align=center bgcolor=#66CCFF>";
echo $row["Year"];
echo "<TD align=center bgcolor=#66CCFF>";
echo $row["Grade"];
echo "</TABLE>";
}
//error message view
if($id > 130) {
echo "<align center><B>0 Results found, The Id Number ($id) was not found, please try again.</B></align>";
}
// End conection to databse
mysql_close($db);
?>
this works great but my problem is with the ?//error message view? part, it says that if the ID number entered was more than ?130? echo the message?.
This is so far good for me, but now I want to make the script automatically search if the id number is there or not, cuz I excluded some numbers between (0 and 130) from my database because my site will only show results of my friends. So how can I let the script look for the id number and echo the same message if ID was not found?
