×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SELECT Query works in phpMyAdmin but not in PHP program

SELECT Query works in phpMyAdmin but not in PHP program

SELECT Query works in phpMyAdmin but not in PHP program

(OP)
Hi,

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

CODE --> MYSQL

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\www\AGC\classregister.php on line 37 (the line beginning $a_fetch)

CODE --> 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



RE: SELECT Query works in phpMyAdmin but not in PHP program

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));

echo "The error is:" . $conn->error;
die(); 

----------------------------------
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

RE: SELECT Query works in phpMyAdmin but not in PHP program

(OP)
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.

RE: SELECT Query works in phpMyAdmin but not in PHP program

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

RE: SELECT Query works in phpMyAdmin but not in PHP program

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close