Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT Query works in phpMyAdmin but not in PHP program 1

Status
Not open for further replies.

rogerte

Programmer
Nov 9, 2001
164
GB
Hi,

If I enter the following SELECT statement in phpMyAdmin it works ok

Code:
SELECT A.class_id, A.attend, A.mem_id, B.firstname, B.lastname FROM attendance AS A INNER JOIN memberdetails AS B ON B.mem_id = A.mem_id WHERE A.class_id=5 ORDER BY B.lastname, B.firstname ASC

but if I try the following in PHP it returns the following error: Fatal error: Call to a member function fetch_array() on boolean in C:\wamp64\ on line 37 (the line beginning $a_fetch)

PHP:
$a_query = $conn->query('SELECT  A.class_id, A.attend, A.mem_id, B.firstname, B.lastname FROM attendance AS A INNER JOIN memberdetails AS B ON B.mem_id = A.mem_id WHERE A.class_id=5 ORDER BY B.lastname. B.firstname ASC') or die(mysqli_error($conn));

$a_fetch = $a_query->fetch_array();

$conn is returned from an initial call to a mysqli connect string, and works fine in other db calls throughout the program.

I have tried enclosing column/table names in backticks, but makes no difference.

Can anyone tell me where I am going wrong?

Thanks
 
It would appear your query is returning a false statement as such $a_query is boolean and not a result object that has a function named fetch_array to call, but is not triggering the die() statement.

What happens if you echo out the error after the query call?

Code:
$a_query = $conn->query('SELECT  A.class_id, A.attend, A.mem_id, B.firstname, B.lastname FROM attendance AS A INNER JOIN memberdetails AS B ON B.mem_id = A.mem_id WHERE A.class_id=5 ORDER BY B.lastname. B.firstname ASC') or die(mysqli_error($conn));

[b]echo "The error is:" . $conn->error;
die();[/b]


----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Thanks for response.

The echo came back as unknown field A.class_id in field roster

So I changed all the occurrences of A. to attendance. and all the B. to memberdetails (obviously removing the AS A and AS B) and it now runs ok.

Puzzling to understand why that should happen.
 
It shouldn't happen. Some issue with the table aliases I would assume.

Anyway, glad you got it sorted.



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
The queries between phpMyAdmin and the PHP script were not identical.

Code:
ORDER BY B.lastname. B.firstname

Your comma lost its tail in the latter query.

You probably caught the error when you changed occurrences of A & B.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top