Hi! I am getting message #1052 - Column 'userlevel' in where clause is ambiguous while running following query:

<?PHP
$query=mysql_query("SELECT mssgs.start_date, mssgs.task, mssgs.status, mssgs.timestamp, mssgs.due_on, mssgs.id, users.fname FROM mssgs
INNER JOIN users ON mssgs.uid=users.uid AND mssgs.userlevel=users.userlevel WHERE status=0 AND userlevel=1 OR userlevel=3");
if(mysql_num_rows($query) > 0)
{

while($row=mysql_fetch_array($query))
{
if($row!=0)
{
$id=$row['id'];
$userlevel=$row['userlevel'];
if($userlevel==1)
{
$userlevel="Manager";
}
elseif($userlevel==2)
{
$userlevel="Administrator";
}
elseif($userlevel==3)
{
$userlevel="Programmer";
}
elseif($userlevel==12)
{
$userlevel="Business Dev. Officer";
}
elseif($userlevel==31)
{
$userlevel="Marketing Executive";
}
echo "<tr align='center'>
<td class='style3'>"; echo $row['fname']; echo "</td>
<td class='style3'>"; echo $userlevel; echo "</td>
<td class='style3'>"; echo $row['task']; echo "</td>
<td class='style3'>"; echo $row['start_date']; echo "</td>
<td class='style3'>"; echo $row['due_on']; echo "</td>
</tr>";
}
}
echo "</table>";
}
?>

In the WHERE clause you have to specify which userlevel to use, the one from mssgs or users.

Thanks a lot for your valuable reply.
I think I need to oil my skills for dealing with joins!!
The problem is resolved for me now but the new problem is, if I run the following query:

"SELECT task.task_id, task.task_to, task.task_from, task.timestamp, task.due_on, task.status, task.task, user.fname FROM task 
INNER JOIN user ON task.userlevel=user.userlevel WHERE task.status=1"

I dont get output even when there is data in the database which has status 1.
Simply no data found message is displayed.

It is possible. Are you sure the task is connected to a user ? You may want to try and get results from phpMyAdmin first, just to test your query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.