Reputation: 22684
I have a mysql join query for retrieving the users a user subscribed to.
SELECT * FROM (subscriptions) JOIN users ON users.userid = subscriptions.following WHERE userid = $userid ORDER BY subscribed desc
In order to ensure that the query is correct, is there a php function that I can use to see what I produced? Maybe get a table structure of the query like below. Or is there another way to get a visual table design of my join?
+----+-------------+-------------------+
| ID | some column | some column |
+----+-------------+-------------------+
| 1 | 102 | 213 |
| 2 | 64 | 23 |
| 3 | 4 | 344 |
+----+-------------+-------------------+
EDIT: It seems that I can test the query in phpmyadmin which produces a table of my join query. This is a great way to get a visual of your query!
Upvotes: 1
Views: 583
Reputation: 48387
It's not clear what you are asking for.
If you want a generic way to test that the results are as you expect - there's no way to this without detailed knowledge of the data.
You shouldn't be testing if your query is correct at run time. And there is no absolute value of 'correct' to measure against.
If you just want to see the meta-data regarding the columns in the returned dataset, use mysql_fetch_field()
Upvotes: 1
Reputation: 26871
Not necessarily a single function, but you can create yourself one using:
mysql_fetchassoc()
to get the resultset as key(col name)/value(col value) pairsarray_keys()
to get all the column names from resultset and create your table headerUpvotes: 1
Reputation: 7722
It's not clear, what you mean. To examine a JOIN
in MySQL do a EXPLAIN SELECT * FROM (subscriptions) JOIN users ON users.userid = subscriptions.following WHERE userid = $userid ORDER BY subscribed desc
and output this result in PHP
Upvotes: 1