I have a database with a table containing user information.
User table: id username password
When the user table is created, I also create a table for each user named after the id. id table: req_id (auto increments) vendor authorized
I am querying the user table and also want to query the newest req_id for each user and return the results. I have to append each row of the results with the users req_id
I have the following code but am not sure on how add the req_id to each row and return the results.
public function getAllUsersInfo() {
$result = mysql_query("select * FROM users");
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
for($i=0;$i<count($rows);$i++) {
$id = $rows[$i]['id']
$req_id = mysql_query("select req_id FROM $id ORDER BY req_id DESC LIMIT 1;");
//Need to append the req_id to the row
}
return $result; //so should be returning id, username, password, req_id
}
<?php
public function getAllUsersInfo() {
$result = mysql_query("select * FROM users");
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
for($i=0;$i<count($rows);$i++) {
$id = $rows[$i]['id'];
$req_result = mysql_query("select req_id FROM $id ORDER BY req_id DESC LIMIT 1;");
$req_row = mysql_fetch_assoc($req_result);
$rows[$i]['req_id'] = $req_row['req_id']; // Add the req_id to the row
}
return $rows;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.