I’m just getting started with the whole php/mysql interaction, but I still don’t want to make a second-rate script just because I don’t know a better way. I built a standard, ugly procedural script for reading from a standard, ugly mysql database. I want to know how I can do one broad query, use one row of it one place, and the rest somewhere else.
I DO NOT want to query the database twice. I just need to know how to access a specific row of a broad query result. Here’s the relevant code:
if ( isset($_GET['some_column']) ) {
$q = 'SELECT * FROM table WHERE some_column = ' . $_GET['some_column'];
$r = mysqli_query ($dbc, $q);
$row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
foreach ($row as $key => $value) {
// do stuf with the values...
} // end FOR EACH
}
$q = 'SELECT * FROM inventory ORDER BY truck_num';
$r = mysqli_query ($dbc, $q);
while ( $row = mysqli_fetch_array($r, MYSQLI_ASSOC) ) {
foreach ($row as $key => $value) {
// do stuff with keys and values...
} // end FOREACH
} // end WHILE
I’m sure there’s some way to get the information from the top query from the bottom query. Can someone help me simplify this code? (no OOP, please)