adski74 Posted November 10, 2006 Share Posted November 10, 2006 I am trying to list booking & notes under dates that have been looped through but I am still having trouble with it :(I cannot get the booking details or note details to loop through the arrary. It just keeps [U]showing the first record multiple times[/U] for both the booking details & note details.[U]Here is an example of what is happening:[/U]1st of November 2006-bookng 1 details-bookng 1 details [B]<-- should be bookng 2 details[/B]-note 1 for this day-note 1 for this day [B]<-- should be note 2 for this day[/B]2nd of November 2006-NO BOOKINGS LISTED FOR THIS DAY-note 1 for this day-note 1 for this day [B]<-- should be note 2 for this day[/B]3rd of November 2006-booking 3 details-booking 3 details [B]<-- should be bookng 4 details[/B]-NO NOTES LISTED FOR THIS DAY[U]This is what it should look like:[/U]1st of November 2006-bookng 1 details-booking 2 details-note 1 for this day-note 2 for this day2nd of November 2006-NO BOOKINGS LISTED FOR THIS DAY-note 1 for this day-note 2 for this day3rd of November 2006-booking 3 details-booking 4 details-NO NOTES LISTED FOR THIS DAYHere is my code:[CODE]<?php// BUILD AN ARRAY FROM OUR BOOKINGS TABLE$sql = "SELECT * FROM akcs_booking_details";$result = mysql_query( $sql );while( $row=mysql_fetch_assoc($result) ){// ADD BOOKING COLUMN DETAILS TO THE ARRAY $booking_date[] = $row['booking_date']; $booking_id = $row['booking_id']; $booking_start_time = $row['booking_start_time']; $booking_finish_time = $row['booking_finish_time']; $client_name = $row['client_name']; $associate_name = $row['associate_name']; $new = $row['new']; $verified = $row['verified']; $price = $row['price']; $location = $row['location']; $cc = $row['cc']; $ca = $row['ca']; $booker = $row['booker']; $completion_comments = $row['completion_comments']; $date_added = $row['date_added'];}mysql_free_result( $result );?><?php// BUILD AN ARRAY FROM OUR NOTES TABLE$sql2 = "SELECT * FROM akcs_booking_notes";$result2 = mysql_query( $sql2 );while( $row=mysql_fetch_assoc($result2) ){// ADD NOTES COLUMN DETAILS TO THE ARRAY $booking_note_start_date[] = $row['booking_note_start_date']; $booking_note_end_date = $row['booking_note_end_date']; $booking_note_id = $row['booking_note_id']; $booking_note_details = $row['booking_note_details']; $booking_note_added = $row['booking_note_added'];}mysql_free_result( $result2 );?><?php $start_date = date('U');$i = 0;while ($i < 50) {$days_to_add = $i * 86400;$end_date = $start_date + $days_to_add;$database_date = date('Y-m-d', $end_date);echo '<h1><strong>' . date('dS \of F Y', $end_date) . ' - ' . $database_date . '</strong></h1>';echo '<p><strong>BOOKING DETAILS</strong></p>';// START LOOP TROUGH BOOKINGS$number_of_bookings = 0;foreach( $booking_date as $b_date ){// IF DATE ($database) EQUALS BOOKING DATE ($b_date) THEN DISPLALY THE BOOKING DETAILSif ($database_date==$b_date) {$number_of_bookings = $number_of_bookings + 1;echo "<p>"; echo $b_date . "<br />"; echo $booking_start_time . "<br />";echo "</p>";}}if ($number_of_bookings==0) {echo "-- NO BOOKINGS FOUND --";}// END LOOP TROUGH BOOKINGSecho '<p><strong>NOTE DETAILS</strong></p>';// START LOOP TROUGH NOTES$number_of_notes = 0;foreach( $booking_note_start_date as $bn_date ){// IF DATE ($database) EQUALS NOTE DATE ($bn_date) THEN DISPLALY THE BOOKING DETAILSif ($database_date>=$bn_date) {if ($database_date<=$booking_note_end_date) {$number_of_notes = $number_of_notes + 1;echo "<p>"; echo $bn_date . " - " . $booking_note_end_date . "<br />"; echo $booking_note_details . "<br />";echo "</p>";}}}if ($number_of_notes==0) {echo "-- NO NOTES FOUND --";}// END LOOP TROUGH NOTEecho '<p> </p>'; $i++;}?>[/CODE]Any help would be great.For more info please also see:http://www.sitepoint.com/forums/showthread.php?p=3155414&posted=1#post3155414Thanks in advance :) Link to comment https://forums.phpfreaks.com/topic/26833-php-loop-array-urgent-help-needed/ Share on other sites More sharing options...
blear Posted November 10, 2006 Share Posted November 10, 2006 [code]while( $row=mysql_fetch_assoc($result2) ){// ADD NOTES COLUMN DETAILS TO THE ARRAY $booking_note_start_date[] = $row['booking_note_start_date']; $booking_note_end_date = $row['booking_note_end_date']; $booking_note_id = $row['booking_note_id']; $booking_note_details = $row['booking_note_details']; $booking_note_added = $row['booking_note_added'];}[/code]The only value that is being put into any form of array is $booking_note_start_date[] = $row['booking_note_start_date']; The rest are being assigned to single-value variables. You have to make all 5 variables into arrays. Link to comment https://forums.phpfreaks.com/topic/26833-php-loop-array-urgent-help-needed/#findComment-122690 Share on other sites More sharing options...
adski74 Posted November 10, 2006 Author Share Posted November 10, 2006 I though it would be something simple :)Do I just add [] to the others vars?Thanks for your help :) Link to comment https://forums.phpfreaks.com/topic/26833-php-loop-array-urgent-help-needed/#findComment-122701 Share on other sites More sharing options...
blear Posted November 10, 2006 Share Posted November 10, 2006 No, you will need to modify your loop structures to use the other indices of the arrays. At present, you're using foreach() which prevents you from indexing the other arrays in a reasonable way. Link to comment https://forums.phpfreaks.com/topic/26833-php-loop-array-urgent-help-needed/#findComment-122705 Share on other sites More sharing options...
adski74 Posted November 10, 2006 Author Share Posted November 10, 2006 Thank blear,So basically I need to rewrite the two foreach() loops so that they can index the other arrays.What loop can I use to replace the foreach to acheive what I need to acheive.Sorry to hassle you but I am running behind on a deadline for this project and I normally use asp.I really appriciate your help :) Link to comment https://forums.phpfreaks.com/topic/26833-php-loop-array-urgent-help-needed/#findComment-122711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.