mysql_query doesnt work in PHP
Posted: Thu Apr 30, 2009 4:39 am
hello. i was wondering if you could help me with this code.
this searches for the name of the person using the keyword
ive checked the keyword entered by the user and its seems fine.. the only problem i that whe I execute this code
in the MYSQL console, it works..
But when I run it in the php file, it always returns 0 results..
I removed once the mysql_num_rows to see if it causes the error but no, it still returns 0 results... what could be the problem with this code..
btw, im using wampserver 2.0e.. (php 5.2.7 and mysql 5.1.30)
this searches for the name of the person using the keyword
Code: Select all
<?php
$sql = mysql_query("SELECT DISTINCT personID, personFirstName, personMiddleInitial, personLastName
FROM person join student
ON person.personid = student.studentID
WHERE personFirstName LIKE '%keyword%' OR personMiddleInitial LIKE '%keyword%' OR personLastName LIKE '%keyword%'");
if(mysql_num_rows($sql)==0)
{echo "<tr> <td colspan=\'2'\ style=\"width: 40em;\"> No records found! </td> </tr>";}
else
{
while($row=mysql_fetch_array($sql))
{
$firstname = $row['personFirstName'];
$lastname = $row['personLastName'];
$middleinitial = $row['personMiddleInitial'];
$pid = $row['personID'];
echo "<tr>";
echo "<td> ". $firstname . " " . $middleinitial . " " . $lastname . "</td>";
echo "<td> <a href=\"viewstudentaccountabilities.php?pid=$pid\" style=\"color:#0066cc;\"> View Accountabilities </td>";
echo "</tr>";
}
}
?>
Code: Select all
SELECT DISTINCT personID, personFirstName, personMiddleInitial, personLastName
FROM person JOIN student
ON person.personid = student.studentID
WHERE personFirstName LIKE '%keyword%' OR personMiddleInitial LIKE '%keyword%' OR personLastName LIKE '%keyword%'
But when I run it in the php file, it always returns 0 results..
I removed once the mysql_num_rows to see if it causes the error but no, it still returns 0 results... what could be the problem with this code..
btw, im using wampserver 2.0e.. (php 5.2.7 and mysql 5.1.30)