I am fairly new to php. Please excuse me if my terms are not correct. I can use and see lots of examples of arrays that loop table rows (all columns).
I want to create/display information from a table like this:
Table example
1, John, Test, bb, cc, dd
2, John, Fram, ee, ff, gg
3, John, Whop, hh, ii, jj
4, Chris, Test, kk, ll, mm
5, Chris, Fram, nn, oo, pp
6, Chris, Whop, qq, rr, ss
(this table will have many more rows and many more names)
Results I want
John
Test, bb, cc, dd
Fram, ee, ff, gg
Whop, hh, ii, jj
Chris
Test, kk, ll, mm
Fram, nn, oo, pp
Whop, qq, rr, ss
(and on and on throughout the whole table)
I have been starting with this code to retrieve the data from the table -
$q = "SELECT id, name, type, data1, data2, data3 FROM table";
$r = mysqli_query($dbc, $q);
Where should I proceed from this point?
Ok your existing 2 statement create and issue a query for execution by MySQL.
You now need to request data back from the database one row at a time so you can do something with the result rows
$q = "SELECT id, name, type, data1, data2, data3 FROM table ORDER BY name";
$result = mysqli_query($dbc, $q);
// first lets check we got a result and not an error
if ( ! $result ) {
echo mysqli_error($dbc);
exit;
}
// get one result row at a time as an object
// each returned row will be an object with
// properties with the same names as the
// column names of the query we are processing
$lastName = NULL;
while ( $row = mysqli_fetch_object($result) ) {
// build required output
if ( $lastname != $row->name ) {
echo '<br>' . $row->name . '<br>';
$lastName = $row->name;
}
echo $row->type . ', '
. $row->data1 . ', '
. $row->data2 . ', '
. $row->data3 . '<br>';
}
$johnQuery = "SELECT type, data1, data2, data3 FROM table WHERE name = 'John'";
$chrisQuery = "SELECT type, data1, data2, data3 FROM table WHERE name = 'Chris'";
$john = mysqli_query($dbc, $johnQuery);
$chris= mysqli_query($dbc, $chrisQuery);
You want like this?