What is wrong with my Query?


function show_join() {
	//$result = mysql_query("SELECT * FROM Persons");
	$userid = $this->session->userdata('user_id');
	$result = $this->db->query("SELECT swap.swapid, swap.offering FROM swap, users_swap WHERE users_swap.user_id = '$userid' AND users_swap.swap_id = swap.swapid");
		echo "<table border='1'>
		<tr>
			<th>swapid</th>
			<th>offering</th>
		</tr>";
		
		while($row = mysql_fetch_array($result))
		  {
			  echo "<tr>";
			  echo "<td>" . $row['swap.swapid'] . "</td>";
			  echo "<td>" . $row['swap.offering'] . "</td>";
			  echo "</tr>";
		  }
		echo "</table>";
}

The error was,


Message: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

?

tnx in advanced.

that’s a php error message which says that the query failed

either that, or it returned no rows and you’re trying to fetch those non-existing rows

that’s just a guess on my part, since i don’t do php (this is the mysql forum)

run the query outside of php, i.e. right in mysql, to see what it does

@r937

I already tested it and the SELECT is fine.
You are right it’s PHP error.

fixing…