Jump to content

Recommended Posts

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>";

 

 

Link to comment
https://forums.phpfreaks.com/topic/179988-whats-better-way/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/179988-whats-better-way/#findComment-949528
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/179988-whats-better-way/#findComment-949875
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.