php - How can I get this SQL query to work...? -
i making game class , decided make leaderboards page. have admin area need grab data both tables in page.
the 2 tables user_settings
, leaderboards
. code on leaderboards.php page:
<?php $records = array(); if ($results = $db->query("select * user_settings union select * leaderboards")) { if ($results->num_rows) { while ($row = $results->fetch_object()) { $records[] = $row; } $results->free(); } } ?> <?php foreach ($records $data) { ?> ...the html etc... <?php } ?>
what need change in order make query work. need change foreach loop? or...? have far needed grad data 1 table i'm not sure how work.
edit:
the user_settings
table admin set config such site name etc. far doing trying select 2 tables without page breaking, @ moment breaking. have feeling foreach loop , of code underneath query. @ moment not want grab data database, want select page doesn't break.
as @kai qing stated using union
. don't know table structures cannot guarantee after believe wanting select 2 tables not share same structure therefore want do:
if ($results = $db->query("select * user_settings, leaderboards")) {
i hope helps.
Comments
Post a Comment