douque2016 2013-06-15 10:24
浏览 20

使用不同的值显示值4次

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);
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值