I'm trying to get values from two different tables and combine to display on json format. The table exp_channel_data contains event and exp_calendar_events contain date and month of event(field start_month and start_day), but the value of start_month and start_day is assigning to every event and displaying. I should show like this.
Father’s Day & VBS Awards Program on June 16.
Bro. N Bulkley preaching in AM Service June 30.
Men’s Prayer Breakfast at 7:30 AM July 7.
Ladies Bible Study – 10 AM July 9.
But instead it is showing
Father’s Day & VBS Awards Program on June 16 Father’s Day & VBS Awards Program on June 30 Father’s Day & VBS Awards Program on July 7 Father’s Day & VBS Awards Program on July 9
Bro. N Bulkley preaching in AM Service June 16 Bro. N Bulkley preaching in AM Service June 30 Bro. N Bulkley preaching in AM Service July 7 Bro. N Bulkley preaching in AM Service July 9
Men’s Prayer Breakfast at 7:30 AM June 16
Men’s Prayer Breakfast at 7:30 AM June 30
Men’s Prayer Breakfast at 7:30 AM July 7
Men’s Prayer Breakfast at 7:30 AM July 9
Ladies Bible Study – 10 AM June 16 Ladies Bible Study – 10 AM June 30 Ladies Bible Study – 10 AM July 7 Ladies Bible Study – 10 AM July 9
Please help me where I went wrong. I'm newbie to php
<?php
$connect = mysql_connect("localhost","pcalaway_119","pcalaway6020358");
mysql_select_db("pcalaway_119");
mysql_query('SET CHARACTER SET utf8');
$result = mysql_query("SELECT field_id_6,start_month,start_day FROM exp_channel_data,exp_calendar_events") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["events"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
if(!empty($row["field_id_6"]))
{
$product = array();
switch($row["start_month"])
{
case 1: $month="January";
break;
case 2: $month="February";
break;
case 3: $month="March";
break;
case 4: $month="April";
break;
case 5: $month="May";
break;
case 6: $month="June";
break;
case 7: $month="July";
break;
case 8: $month="August";
break;
case 9: $month="September";
break;
case 10: $month="October";
break;
case 11: $month="November";
break;
case 12: $month="December";
break;
}
$product["event"] = $row["field_id_6"]." on ".$month." ".$row["start_day"];
// push single product into final response array
array_push($response["events"], $product);
}
else{
continue;
}
}
// success
$response["success"] = 1;
$preserved = array_reverse($response, true);
// echoing JSON response
echo json_encode($preserved);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>