davids701124 Posted November 2, 2009 Share Posted November 2, 2009 I wanna push 2 arrays, event array and journal array, into the other array, so I can get the all result once. do I need to make the 2 array be variables first?? or just push them into the array directly anyway? this is what I have now: //check out baby's due date $weeks_expected = 42; $baby_id = $_SESSION['baby_id']; $days_expected = $weeks_expected * 7; $sql = "SELECT SUBDATE(due_date, INTERVAL $days_expected DAY) AS begin_date FROM baby WHERE baby_id = {$baby_id}"; $begin_date_query = mysql_query( $sql ); while ( $row = mysql_fetch_array($begin_date_query)){ print "Your baby's due date from baby table: ". $row["begin_date"] . "<br>"; $begin_date = $row['begin_date']; } //check out the posts for this baby id. $sql = "SELECT (DATEDIFF(post_date, '$begin_date') + 1) AS num_day, DATE(post_date) AS post_date, post_title, post_des FROM post WHERE baby_id = {$baby_id}"; print "!!!!! $sql !!!!!"; $posts_query = mysql_query( $sql ); while ( $row = mysql_fetch_assoc($posts_query)) { $num_day = $row['num_day']; $post_date = $row['post_date']; $post_title = $row['post_title']; $post_des = $row['post_des']; $posts[$num_day]['post_date'] = $post_date; $posts[$num_day]['post_title'] = $post_title; $posts[$num_day]['post_des'] = $post_des; } //check out the events for this baby id. $sql = "SELECT (DATEDIFF(start_datetime, '$begin_date') + 1) AS num_day, DATE(start_datetime) AS start_datetime, event_title, event_des FROM event WHERE baby_id = {$baby_id}"; $events_query = mysql_query( $sql ); while ( $row = mysql_fetch_assoc($events_query)) { $num_day = $row['num_day']; $event_date = $row['start_datetime']; $event_title = $row['event_title']; $event_des = $row['event_des']; $events[$num_day]['start_datetime'] = $start_datetime; $events[$num_day]['event_title'] = $event_title; $events[$num_day]['event_des'] = $event_des; } print "<PRE>"; print_r($posts); print "<BR>"; print_r($events); print "<BR>"; print "</PRE>"; Quote Link to comment https://forums.phpfreaks.com/topic/179988-whats-better-way/ Share on other sites More sharing options...
JAY6390 Posted November 2, 2009 Share Posted November 2, 2009 If you are wanting to merge two arrays together take a look at http://www.php.net/array_merge Quote Link to comment https://forums.phpfreaks.com/topic/179988-whats-better-way/#findComment-949525 Share on other sites More sharing options...
mikesta707 Posted November 2, 2009 Share Posted November 2, 2009 if you want to push the arrays into the new array, you can just do something like $array[] = $otherArray; //or $array[] = array("stuff", "in", "other", "array"); However, look into array_merge as Jay said if you want to merge the arrays Quote Link to comment https://forums.phpfreaks.com/topic/179988-whats-better-way/#findComment-949528 Share on other sites More sharing options...
davids701124 Posted November 2, 2009 Author Share Posted November 2, 2009 thank you guys! Quote Link to comment https://forums.phpfreaks.com/topic/179988-whats-better-way/#findComment-949533 Share on other sites More sharing options...
davids701124 Posted November 3, 2009 Author Share Posted November 3, 2009 after using array_merage(), i think the result is a little bit different from what I tend to do. I think what I need is multidimensional arrays, say $posts and $events are array and containing some information already, and I wanna they are contained in a new array.So how to use it? Quote Link to comment https://forums.phpfreaks.com/topic/179988-whats-better-way/#findComment-949875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.