mysqli-fetch-array

How can I use mysqli_fetch_array() twice?

安稳与你 提交于 2021-02-05 11:42:10
问题 I am using the entries of a db to fill a row and a column in a table. But I cannot access the SQL returned data twice using mysqli_fetch_array() twice. This doesn't work: //Copy the result $db_res = mysqli_query( $db_link, $sql ); $db_res2=$db_res; //Top row while ($row = mysqli_fetch_array( $db_res, MYSQL_ASSOC)) { echo "<td>". $row['Title'] . "</td>"; } //leftmost column while ($row = mysqli_fetch_array( $db_res2, MYSQL_ASSOC)) { echo "<tr>"; echo "<td>". $row['Title'] . "</td>"; ..... echo

Echo contents of JOIN SQL tables with MySQLi

馋奶兔 提交于 2021-01-28 06:07:59
问题 I'm working on a system, and this module is supposed to echo the contents of the database. It worked perfectly until I added some JOIN statements to it. I've checked and tested the SQL code, and it works perfectly. What's not working is that part where I echo the content of the JOINed table. My code looks like this: $query = "SELECT reg_students.*, courses.* FROM reg_students JOIN courses ON reg_students.course_id = courses.course_id WHERE reg_students.user_id = '".$user_id."'"; $result =

How to display grouped data in separate tables with a PHP loop?

泪湿孤枕 提交于 2020-01-21 09:10:45
问题 I am new to phpmysqli. Here is what I have and what am trying to achieve: I will update this based on the recommendations; Database sample data I want to display the data on one page with separate tables for each student based on their sid. This is what I have tried so far; <?php include_once 'dbcon.php'; $results = $MySQLiconn->query('SELECT * FROM activitybook'); $students = []; foreach ( $results->fetch_array() as $activity ) { $students[$activity['sid']][] = $activity; } foreach($students

How to display grouped data in separate tables with a PHP loop?

感情迁移 提交于 2020-01-21 09:10:07
问题 I am new to phpmysqli. Here is what I have and what am trying to achieve: I will update this based on the recommendations; Database sample data I want to display the data on one page with separate tables for each student based on their sid. This is what I have tried so far; <?php include_once 'dbcon.php'; $results = $MySQLiconn->query('SELECT * FROM activitybook'); $students = []; foreach ( $results->fetch_array() as $activity ) { $students[$activity['sid']][] = $activity; } foreach($students

How to display grouped data in separate tables with a PHP loop?

我怕爱的太早我们不能终老 提交于 2019-12-01 11:44:14
I am new to phpmysqli. Here is what I have and what am trying to achieve: I will update this based on the recommendations; Database sample data I want to display the data on one page with separate tables for each student based on their sid. This is what I have tried so far; <?php include_once 'dbcon.php'; $results = $MySQLiconn->query('SELECT * FROM activitybook'); $students = []; foreach ( $results->fetch_array() as $activity ) { $students[$activity['sid']][] = $activity; } foreach($students as $sid=>$activities) { foreach($activities as $activity) { echo "<table><tr> <th>SID</th> <th>Date<