PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE booking (id int, name varchar(20)); INSERT INTO booking (id, name) VALUES (1, 'Booking 1'), (2, 'Booking 2'); CREATE TABLE booking_line (id int, booking_id int,is_repeat int, description varchar(20)); INSERT INTO booking_line (id, booking_id,is_repeat, description) VALUES (3, 1,1, 'Line 1'),(3, 1,0, 'Line 1'), (2, 1,0, 'Line 2'), (4, 2,0, 'Line 3');
Copy Clear
Copy Format Clear
<?php $repeat_query= "SELECT a.id, a.booking_id,a.description, b.id AS book_id,b.name FROM booking_line a JOIN booking b ON a.booking_id = b.id WHERE a.is_repeat = '1' ORDER BY b.name"; $i=0; if ($r_result = mysqli_query($conn, $repeat_query)) { // Return the number of rows in result set $rowcount = mysqli_num_rows( $r_result ); // Display result //echo $rowcount."<br>"; $repeat = array(); $repeat_user = array(); while($repeat_row = mysqli_fetch_assoc($r_result)) { $repeat[] = $repeat_row; } } print_r($repeat);
Show:  
Copy Clear