Jump to content

what's better way


davids701124

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.