Kyluke
July 28th, 2011, 08:10 PM
Hey I have a website with a mysql database.
Now I need to have a search function built in but for some reason my code only ever produces either the first line (no matter what) or the whole table.
Here is my code and i want it to return only one row with the correct data
<?php
mysql_connect ("localhost", "chaos_theory","12345") or die (mysql_error());
mysql_select_db ("students");
$term = $_GET['student_number'];
$sql = mysql_query("select * from students where student_number like '%$term%'");
while ($row = mysql_fetch_array($sql)){
echo 'ID: '.$row['id_number'];
echo '<br/> First Name: '.$row['student_number'];
echo '<br/> Last Name: '.$row['first_name'];
echo '<br/> Phone: '.$row['surname'];
echo '<br/><br/>';
}
?>
Now I need to have a search function built in but for some reason my code only ever produces either the first line (no matter what) or the whole table.
Here is my code and i want it to return only one row with the correct data
<?php
mysql_connect ("localhost", "chaos_theory","12345") or die (mysql_error());
mysql_select_db ("students");
$term = $_GET['student_number'];
$sql = mysql_query("select * from students where student_number like '%$term%'");
while ($row = mysql_fetch_array($sql)){
echo 'ID: '.$row['id_number'];
echo '<br/> First Name: '.$row['student_number'];
echo '<br/> Last Name: '.$row['first_name'];
echo '<br/> Phone: '.$row['surname'];
echo '<br/><br/>';
}
?>