php tp5数据表中信息拼接json字符串 40C

表一:activity
图片说明
表二:standard
图片说明
activity-id 是两表关联字段
两表内容动态改变,现在需要利用tp5写一个方法,前端调用,然后返回一个json串,json串格式如下:
图片说明
主要就是把standard中activityid一致的放到对应activity的childMenus中
用的tp5,该怎么写?

3个回答

db::query('seletc *,concat(字段1,字段2) from 表名 ');

两表联合查询不可以吗???

$model = new Model();
$result1 = $model->query('select * from activity');
foreach($result1 as $key => $val){
$result2 = $model->query('select * from standard where activity_id=' . $val['id']);
$result1[$key]['childMenus'] = $result2;
}
echo json_encode($result1);

            这应该是你想要的吧
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
tp5 如何查询mysql中json数据

数据库中保存有json数据如下: 例:表 so_custom id custom_id content 1 1 {"buy":"2","sell":"3","stock":"1,2,3"} 2 4 {"buy":"2","sell":"3","stock":"1,4"} 3 6 {"buy":"2","sell":"3","stock":"1,22,3"} 4 7 {"buy":"2","sell":"3","stock":"1"} 现在只知道 stock中有3,如何通过这个条件去找出相应的custom_id,tp5的查询写法是什么? 这种写法($this->model->json(['content'])->where('content->stock',3)->select())只能在stock =3 的数据,无法找出 stock 包含 1,2,3 的数据,

PHP:json_decode无法读取转义的字符串

<div class="post-text" itemprop="text"> <p>i want to read a .json file using file_get_contents which returns a string. Then i use json_decode to create an array/object of it. Everything works.</p> <p>My problem is that sometimes the string in the json file includes regex expressions. These can not be decoded! Therefore the following notice message:</p> <pre><code>Notice: Trying to get property 'Data' of non-object in </code></pre> <p>After a quick google search i found out that i have to double escape them. I tried to change it in the json file - it works. </p> <pre><code>From: "Block Proxy URL": "somesite.ab123regex(\d\d\d).top/fyli.php", To: "Block Proxy URL": "somesite.ab123regex(\\d\\d\\d).top/fyli.php", </code></pre> <p>But i receive that file generated by an appliance so i can't change it every time manually.</p> <p>So consequently i tried to automate it:</p> <pre><code>$archer_json_data = file_get_contents($filename); str_replace("\\", "\\\\", $archer_json_data); $archer_json_array = json_decode($archer_json_data)-&gt;Data; </code></pre> <p>which does not work. I also tried addslashes instead of str_replace, it does not work. why? According to the replies of my quick google search it works for them.</p> <p>For debugging purposes i echo'ed <code>archer_json_data</code> before str_replace and after.. they are exactly the same. Why does my str_replace not work?</p> </div>

如何在没有双重编码的情况下从json字符串数组创建json字符串?

<div class="post-text" itemprop="text"> <p>In PHP, I have an array of JSON strings. I would like to know if there is a way to create a JSON string of this array without double encoding the original JSON.</p> <p>The array looks like this:<br> <a href="https://i.stack.imgur.com/jVumc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jVumc.png" alt="enter image description here"></a></p> <p>The resulting call to <code>json_encode($myArray, JSON_UNESCAPED_SLASHES)</code> looks like this:</p> <pre><code>{ "invoice": "{\"order_id\":\"1\",\"store_id\":\"1\",\"customer_id\":\"2\",\"billing_address_id\":\"2\",\"shipping_address_id\":\"1\",\"global_currency_code\":\"USD\",\"base_currency_code\":\"USD\",\"store_currency_code\":\"USD\",\"order_currency_code\":\"USD\",\"store_to_base_rate\":\"0.0000\",\"store_to_order_rate\":\"0.0000\",\"base_to_global_rate\":\"1.0000\",\"base_to_order_rate\":\"1.0000\",\"items\":{},\"total_qty\":1,\"subtotal\":59.95,\"base_subtotal\":59.95,\"subtotal_incl_tax\":59.95,\"base_subtotal_incl_tax\":59.95,\"grand_total\":64.95,\"base_grand_total\":64.95,\"discount_amount\":0,\"base_discount_amount\":0,\"shipping_amount\":\"5.0000\",\"base_shipping_amount\":\"5.0000\",\"shipping_incl_tax\":\"5.0000\",\"base_shipping_incl_tax\":\"5.0000\",\"shipping_tax_amount\":\"0.0000\",\"base_shipping_tax_amount\":\"0.0000\",\"shipping_discount_tax_compensation_amount\":\"0.0000\",\"base_shipping_discount_tax_compensation_amnt\":null,\"tax_amount\":0,\"base_tax_amount\":0,\"discount_tax_compensation_amount\":0,\"base_discount_tax_compensation_amount\":0,\"base_cost\":0,\"can_void_flag\":false,\"state\":2}", "items": "{\"totalRecords\":0,\"items\":[{\"order_item_id\":\"1\",\"product_id\":\"1\",\"sku\":\"TP1\",\"name\":\"Test Product ONE\",\"description\":null,\"price\":\"59.9500\",\"base_price\":\"59.9500\",\"base_cost\":null,\"price_incl_tax\":\"59.9500\",\"base_price_incl_tax\":\"59.9500\",\"weee_tax_applied\":\"[]\",\"weee_tax_applied_amount\":null,\"weee_tax_applied_row_amount\":0,\"base_weee_tax_applied_amount\":null,\"base_weee_tax_applied_row_amnt\":null,\"weee_tax_disposition\":null,\"base_weee_tax_disposition\":null,\"weee_tax_row_disposition\":0,\"base_weee_tax_row_disposition\":0,\"qty\":\"1.000000\",\"invoice\":{},\"parent_id\":null,\"store_id\":\"1\",\"row_total\":59.95,\"base_row_total\":59.95,\"row_total_incl_tax\":59.95,\"base_row_total_incl_tax\":59.95,\"tax_amount\":0,\"base_tax_amount\":0,\"discount_tax_compensation_amount\":0,\"base_discount_tax_compensation_amount\":0,\"base_weee_tax_applied_row_amount\":0}]}", "billing-address": "{\"entity_id\":\"2\",\"parent_id\":\"1\",\"customer_address_id\":\"3\",\"quote_address_id\":null,\"region_id\":\"24\",\"customer_id\":null,\"fax\":null,\"region\":\"Indiana\",\"postcode\":\"47933\",\"lastname\":\"Thompson\",\"street\":\"204 N Grace Avenue\",\"city\":\"Crawfordsville\",\"email\":\"mitch@stdfasdfti.org\",\"telephone\":\"(987)987-9877\",\"country_id\":\"US\",\"firstname\":\"Mitchell\",\"address_type\":\"billing\",\"prefix\":null,\"middlename\":null,\"suffix\":null,\"company\":null,\"vat_id\":null,\"vat_is_valid\":null,\"vat_request_id\":null,\"vat_request_date\":null,\"vat_request_success\":null}", "shipping-address": "{\"entity_id\":\"1\",\"parent_id\":\"1\",\"customer_address_id\":\"3\",\"quote_address_id\":null,\"region_id\":\"24\",\"customer_id\":null,\"fax\":null,\"region\":\"Indiana\",\"postcode\":\"47933\",\"lastname\":\"Thompson\",\"street\":\"204 N Grace Avenue\",\"city\":\"Crawfordsville\",\"email\":\"mitch@sasdfdsfatti.org\",\"telephone\":\"(987)987-9877\",\"country_id\":\"US\",\"firstname\":\"Mitchell\",\"address_type\":\"shipping\",\"prefix\":null,\"middlename\":null,\"suffix\":null,\"company\":null,\"vat_id\":null,\"vat_is_valid\":null,\"vat_request_id\":null,\"vat_request_date\":null,\"vat_request_success\":null}" } </code></pre> <p>I understand WHY its doing it this way, i'd just rather it not. Also, ideally i'd like to avoid using a str_replace. Ideas?</p> </div>

tp5中用 foreach为什么报错 非法字符串偏移

# HTML代码 ``` <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>教师管理</title> </head> <body> <table> <tr> <th>姓名</th> </tr> <tr> {foreach $row as $v} <td> {$v.name}</td> <td><a style="margin-right: 10px" href="{:url('Index/urlid')}?id={$v.id}">删除</a><a href="{:url('Index/cahkan')}?id={$v.id}">查看</a></td> </tr> <br/> {/foreach} </table> </body> </html> ``` # cahkan Html代码 ``` <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>教师管理</title> </head> <body> <table> <tr> <th>序号</th> <th>姓名</th> <th>性别</th> <th>邮箱</th> <th>用户名</th> <th>操作</th> </tr> <tr> {foreach $row as $v} <td> {$v.name}</td> <td> {$v.sie}</td> <td> {$v.emli}</td> <td> {$v.usename}</td> {/foreach} </tr> </table> </body> </html> ``` # 控制器代码 ``` public function biaodan(){ $row=db('biaodan')->select(); $this->assign('row',$row); return $this->fetch(); } public function urlid(){ $str=input('id'); $row=db('biaodan')->where('id',$str)->delete(); if($row>0){ $this->error('操作成功','biaodan'); } } public function cahkan(){ $str1=input('id'); echo $str1; $row=db('biaodan')->where('id',$str1)->find(); $this->assign('row',$row); return $this->fetch(); } ```

php 返回JSON数据 如何提取数据

返回的JSON数据格式是这样的 ``` data=%7B%22site_id%22%3A+%221596050222807053%22%2C+%22ad_id%22%3A+%22%22%2C+%22data%22%3A+%5B%7B%22lable%22%3A+%22%5Cu8bfe%5Cu7a0b%5Cu9009%5Cu62e9%22%2C+%22id%22%3A+1596050222818312%2C+%22value%22%3A+%22%5Cu897f%5Cu70b9%5Cu70d8%5Cu7119%22%2C+%22label%22%3A+%22%5Cu8bfe%5Cu7a0b%5Cu9009%5Cu62e9%22%7D%2C+%7B%22lable%22%3A+%22%5Cu59d3%5Cu540d%22%2C+%22id%22%3A+1596050222818328%2C+%22value%22%3A+%22%5Cu6d4b%5Cu8bd5%22%2C+%22label%22%3A+%22%5Cu59d3%5Cu540d%22%7D%2C+%7B%22lable%22%3A+%22%5Cu7535%5Cu8bdd%22%2C+%22id%22%3A+1596050222818344%2C+%22value%22%3A+%2213488888888%22%2C+%22label%22%3A+%22%5Cu7535%5Cu8bdd%22%7D%5D%7D ``` 如何提取里面的姓名、电话等信息? 注:JSON是从另外一个平台提取的,前端是不能操作。 我用站长工具去 解码就可以出来, 但是直接用PHP urldecode 转换 ``` data={“site_id“: “1596050222807053“ “ad_id“: ““ “data“: [{“lable“: “u8bfeu7a0bu9009u62e9“ “id“: 1596050222818312 “........ ``` 符号是中文的、过滤了 \

mysql关联表查询如何返回像json格式的数据呢?

比如这样 表1![图片说明](https://img-ask.csdn.net/upload/201905/06/1557124341_918625.png) 表2![图片说明](https://img-ask.csdn.net/upload/201905/06/1557124396_425261.png) 表1 item和表2item_id关联外键了已经 要怎么写才能输出类似json这种数据![图片说明](https://img-ask.csdn.net/upload/201905/06/1557124541_824379.png) 老哥们指导一下.

使用PHP将JSON数据保存到MySQL中

<div class="post-text" itemprop="text"> <p>Im getting json data from another server and need thouse data to be saved on mysql.I tryed this code but theres a problem when i run this code i get : Illegal string offset for each VALUES. I hope I made things clear if there's anything I didn't explain please do tell.</p> <pre><code> &lt;?php require('db.php'); $url = 'xxxxx'; $data =json_encode(array('xxx' =&gt; 'xxxx', 'xxxx' =&gt; 'xxxxx', 'xxxx' =&gt;'xxxx', 'xxxx' =&gt;'xxxx', 'xxxx' =&gt;'xxxx') ); $options = array( 'http' =&gt; array( 'header' =&gt; "Content-type: application/json", 'method' =&gt; 'POST', 'content' =&gt; $data ) ); $context= stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { } echo $result ; foreach ((array)$result as $row) { $table="INSERT INTO table_name(xxx,xxx,xx,xxx,xx,xxx,xxx,xxxx,xxx) VALUES('".$row["xxxx"]."','".$row["xxx"]."','".$row["xxx"]."','".$row["xxx"]."','".$row["xxx"]."','".$row["xxx"]."','".$row["xxx"]."','".$row["xxx"]."','".$row["xxxx"]."')"; if ($conn-&gt;query($table ) === TRUE) { echo "Record added Successfully&lt;br&gt;"; } else { echo "Error: " . $insert_value . "&lt;br&gt;" . $con-&gt;error; } } ?&gt; </code></pre> </div>

PHP非法字符串偏移错误

<div class="post-text" itemprop="text"> <p>I have this code I don't know why I get error from it.</p> <pre><code>if( ! in_array($repeatType, ['monthly', 'weekly', 'daily'])){ // do somehting } $monthly = ['two_years' =&gt; 26, 'offset_const' =&gt; 4, 'add_unite' =&gt; 'weeks']; $weekly = ['two_years' =&gt; 52*2, 'offset_const' =&gt; 1, 'add_unite' =&gt; 'weeks']; $daily = array('two_years' =&gt; 365*2, 'offset_const' =&gt; 1, 'add_unite' =&gt; 'days'); for ($i=0; $i &lt; $$repeatType['two_years']; $i++) { #&lt;--- here I get the error // ..... // rest of the code </code></pre> <p>This is so weird cause I have checked <code>var_dump($$repeatType)</code> output, it seems fine:</p> <pre><code>array(3){["two_years"]=&gt;int(730)["offset_const"]=&gt;int(1)["add_unite"]=&gt;string(4)"days"} </code></pre> </div>

如何从PHP中将此SimpleXMLElement中的值作为字符串获取

<div class="post-text" itemprop="text"> <p>Say I have a variable called $myXMLElement and when I dump the variable it looks like this.</p> <pre><code>SimpleXMLElement Object ( [@attributes] =&gt; Array ( [id] =&gt; 7 ) [0] =&gt; Kirkpatrick ) </code></pre> <p>How do I grab the value of Kirkpatrick in PHP</p> </div>

在sql语句中,字符串比较,比的是什么?

如题,在sql语句中,字符串 >= 字符串,这个条件比的是什么?,求大神解答一下。 ``` select * from table where varcharColumen >= '字符串' ```

如何将tp5的Mysql数据表里面的数据,全部显示在HTML自定义好的TABLE中?

![图片说明](https://img-ask.csdn.net/upload/201908/26/1566783052_904264.jpg) 我现在这个方法,一直循环显示同一条数据啊,要怎么样才能不重复显示数据呢?没有设置id主键,比如我要循环显示100条数据里面的“性别”那查询语句怎么写呢?tp5.0

mysql数字类型存储,为什么查询时返回的是字符串?

数据库保存的int类型,查询后返回的结果是字符串类型。。。为什么查询时返回的是字符串,不是int类型?

TP5当中我的数据库表里有这个字段名,为什么还是找不到?

数据库表中明明有`admin_name`这个字段名,但是为什么会出现找不到的情况? ![图片说明](https://img-ask.csdn.net/upload/201805/29/1527592859_130501.png) 以下是控制器下的代码: ![图片说明](https://img-ask.csdn.net/upload/201805/29/1527593139_509542.png) 数据库方面: ![图片说明](https://img-ask.csdn.net/upload/201805/29/1527593189_715264.png) ![图片说明](https://img-ask.csdn.net/upload/201805/29/1527593209_563100.png)

从嵌套的json中提取数据

<div class="post-text" itemprop="text"> <p>I've a nested JSON code as below:</p> <pre><code> fn({ "processingDurationMillis": 714, "authorisedAPI": true, "success": true, "airline": "MH", "validCreditCards": [ "AX", "CA", "VI" ], "paypal": true, "outboundOptions": [ { "optionId": 0, "flights": [ { "flightNumber": "0066", "departureAirport": { "code": "KUL", "name": "Kuala Lumpur Intl", "city": "Kuala Lumpur", "country": "Malaysia", "timezone": "Asia/Kuala_Lumpur", "lat": 2.745578, "lng": 101.709917, "terminal": null, "gate": null }, "arrivalAirport": { "code": "ICN", "name": "Incheon Intl", "city": "Seoul", "country": "South Korea", "timezone": "Asia/Seoul", "lat": 37.469075, "lng": 126.450517, "terminal": null, "gate": null }, "marketingAirline": "MH", "mealIndicator": "M", "allowedSsrs": { }, "operatingAirline": null, "equipment": "333", "equipmentName": "Airbus A330-300", "flightRPH": 10101, "comments": [ "MH CODESHARE WITH KE" ], "depScheduled": "2015-04-28T23:30:00.000+08:00", "arrScheduled": "2015-04-29T07:10:00.000+09:00", "depEstimated": null, "depActual": null, "arrEstimated": null, "arrActual": null, "eligibleForEticketing": true, "cabin": "ECONOMY", "fareMarketingType": "LOWEST", "rbd": "O", "seatsAvailable": 2, "durationMinutes": 400, "minutesToScheduledFlightDeparture": 7877 } ], "stopOvers": [ ], "fareDetails": { "perPassengerJourneyFares": [ { "passengerType": "ADT", "fare": "852.93", "currencyCode": "MYR" } ], "perPassengerTripTaxes": [ { "passengerType": "ADT", "totalTax": "68.90", "taxes": [ { "code": "MY", "amount": "65.00", "currency": "MYR" }, { "code": "D8", "amount": "3.90", "currency": "MYR" } ] } ], "journeyFare": "852.93", "totalTripFare": "921.90", "fareCurrency": "MYR" }, "magicString": "mBkCLcD63tlNguPp1ZhbqE99F5uY2SahL3rnMrgD5/Bylh3q2u2UfDCV5DaiQ/Okp6VkdUvBjnUrsiHiL2T/E9xTWTFoSQBw18t2HPQI6KAPGlWNDjDXl8Tiz63YtQ+/WRX3RSJ62KM5azSj6piLWeBN8wvZy1b8dJssMw8dWNkmCwjNxbGor0mepeewSu8ebiYtoHfaDmcd1xdk+kczn2PMjXxUVdFgvXJNnDOke71H/cw5Njh2bAetCQv+fqluAQfmKutZczIR6hJG2u+kJSLaVeUfpR9RNMeN3VvLUZNbLE0Bxe0UtbEHnSLRBRVE7WfDeofOg7iiIYKy42Z1l4T8CIvy92x/vVHoe2oOpONS7xH8YlBG86BOs1eNeFTQOZ3uMzExOxrsJl/DaQOAW3hrJ4Mv4IiSuwli69r8wHbT/iw3JYEGDPnsZA81W4KJJl4bkAMuN7PD4DygdGlRFKYPWcyyYW+wlFge8v//d+ndyrMVzQOh9HPq7nLv8lWPIKK/zzKjSJGv4jtNrNuvyP5/OXzS392P8tZLEKgwuq3LSnZX3P+mSvnFU3LgL+6VjrPLkiAC9pzEF+NnRYzGKp+Hv8nAFhzEOGuxXwXkYAzcFwHlnRluJ894K7GbP8dwRNE52NGzufxrS77DAtVCc1KaW4ZfJ920N126DP05JvRkL6TOepG7MDhV1sCL72P7sICTOR+ROAYKmAedI9lpEBkMtja/siHb581eHZ15m/Tp9VFD8Q62wDFgzUb6fMD8/5yXK/gt4BCWOcbxNqD3nva8JQ2pVZu22JJFg+SlGkVLxTAplQx4HyRXryUjXL4kUais+UVx0tBBWDIuVpoZGdEIUA/eQ8xBXvj8fusswCc5ut3pmykk50Hu0TXhv40iIjP9CtclqyH13Xl6dYJ4n24utUgrhyn42UorGKJLimtxLlj8Wwf7QFNMVPnLrkAfqmJ/80YaF/i43H3IxuueFPIpC2QSAUN/5KtB3HSBKHUgb/cQgJlPtBrPvrjjsaiCmz9HEdGbnWryMnq7mxrPmeDEHnFYL4WY8gu0N75QalXsbAwEhLv0RunX1Krk04o6p1uf20wEtPGXSjPJrofpJLlOWAr019mGfXnBvodVQbB5sMDVlD3JFxysw4+9KElFcF+FFzFZZDxUUWAMG5p6U+HIoeC13mMZ63hpU+KZNa/0meLTSGMxce919qRyEt1DxU4Ty3u5fJ5NJc028NF6LLpDHs7uNok8AkI3yDaLGsLT12rNqjLgOelHjTQxwX5ez1JjUjalPm00sgcq4RhTsOQaOAIqHf4mq1zNES3uyiWSK0MmGugxvGZ1RDAq9G/E", "seatsAvailable": [ 2 ], "corporateAccount": false, "flightCanBeHeld": true, "durationMinutes": 400, "gaFareDetails": { "perPassengerJourneyFares": [ { "passengerType": "ADT", "fare": "852.93", "currencyCode": "MYR" } ], "perPassengerTripTaxes": [ { "passengerType": "ADT", "totalTax": "68.90", "taxes": [ { "code": "MY", "amount": "65.00", "currency": "MYR" }, { "code": "D8", "amount": "3.90", "currency": "MYR" } ] } ], "journeyFare": "852.93", "totalTripFare": "921.90", "fareCurrency": "MYR" }, "adobeFareDetails": { "perPassengerJourneyFares": [ { "passengerType": "ADT", "fare": "234.81", "currencyCode": "USD" } ], "perPassengerTripTaxes": [ { "passengerType": "ADT", "totalTax": "18.97", "taxes": [ { "code": "MY", "amount": "17.89", "currency": "USD" }, { "code": "D8", "amount": "1.07", "currency": "USD" } ] } ], "journeyFare": "234.81", "totalTripFare": "253.80", "fareCurrency": "USD" }, "userAgentFareDetails": { "perPassengerJourneyFares": [ { "passengerType": "ADT", "fare": "234.81", "currencyCode": "USD" } ], "perPassengerTripTaxes": [ { "passengerType": "ADT", "totalTax": "18.97", "taxes": [ { "code": "MY", "amount": "17.89", "currency": "USD" }, { "code": "D8", "amount": "1.07", "currency": "USD" } ] } ], "journeyFare": "234.81", "totalTripFare": "253.80", "fareCurrency": "USD" }, "directFlight": true, "eligibleForeTicketing": true, "lowestSeatCount": 2 } ], "departureAirport": { "code": "KUL", "name": "Kuala Lumpur Intl", "city": "Kuala Lumpur", "country": "Malaysia", "timezone": "Asia/Kuala_Lumpur", "lat": 2.745578, "lng": 101.709917, "terminal": null, "gate": null }, "arrivalAirport": { "code": "ICN", "name": "Incheon Intl", "city": "Seoul", "country": "South Korea", "timezone": "Asia/Seoul", "lat": 37.469075, "lng": 126.450517, "terminal": null, "gate": null }, "apiRequired": true, "fareRules": [ { "id": 40, "order": 0, "priority": 0, "code": "Lowest", "name": "MHlow", "value": "Economy Class Fares", "listFareRules": [ { "id": 10, "order": 0, "code": "", "name": "Discount level", "value": "Up to 80%" }, { "id": 20, "order": 1, "code": "", "name": "Where to buy", "value": "All channels" }, { "id": 30, "order": 2, "code": "", "name": "Advance purchase", "value": "Applies" }, { "id": 40, "order": 3, "code": "", "name": "Payment", "value": "Ticket dateline applies" }, { "id": 50, "order": 4, "code": "", "name": "Baggage allowance", "value": "2pc/30kg" }, { "id": 60, "order": 5, "code": "", "name": "Advance seat selection", "value": "Not allowed" }, { "id": 70, "order": 6, "code": "", "name": "Enrich miles", "value": "Nil" }, { "id": 80, "order": 7, "code": "", "name": "Change of booking", "value": "Not allowed" }, { "id": 90, "order": 8, "code": "", "name": "Upgrade", "value": "Not allowed" }, { "id": 100, "order": 9, "code": "", "name": "Stand by at the airport", "value": "Not allowed" }, { "id": 110, "order": 10, "code": "", "name": "No show", "value": "Penalty applies" }, { "id": 120, "order": 11, "code": "", "name": "Refund", "value": "No Refund" } ], "listFareNotes": [ { "id": 10, "order": 0, "code": "", "name": "Important Notice", "value": "" }, { "id": 15, "order": 1, "code": "", "name": "", "value": "" }, { "id": 20, "order": 2, "code": "", "name": "1.", "value": "Generic attributes shown only applies to MH operated flights. MH3000-3999, MH5200-5999 and MH9000-9999 Series flights are subject to their own rules. Please contact MH Call Center or ticket offices for actual fare rules." }, { "id": 30, "order": 3, "code": "", "name": "2.", "value": "For transpacific and transatlantic flights, the following baggage allowances apply: Economy - 2 pieces (23kg each piece), First and Business - 2 pieces (32kg each piece)." }, { "id": 50, "order": 5, "code": "", "name": "3.", "value": "Upgrade, standby at the airport and refund fees for specific routes can be obtained from subsequent booking pages." }, { "id": 60, "order": 6, "code": "", "name": "4.", "value": "Standby at the airport denotes the same day for an earlier flight." }, { "id": 70, "order": 7, "code": "", "name": "5.", "value": "Fare rules shown are indicative only. Please call our Contact Center to check the detailed fare rules." }, { "id": 80, "order": 8, "code": "", "name": "", "value": "Should there be any discrepancy between the above information and the terms and conditions (T&amp;C) published in the fare rules, then the T&amp;C in the fare rules shall prevail." } ] } ], "Errors": [ ], "Warnings": [ ] }) </code></pre> <p>when i trying to get flight number from the json above, it return me a error."Trying to get property of non-object" and "Invalid argument supplied for foreach()".</p> <p>here is my code:</p> <pre><code>$flight = json_decode($result,true); $info = $flight-&gt;outboundOptions-&gt;flights; foreach ($info as $flightinfo){ echo $flightinfo['flightNumber']; } </code></pre> <p>I know this is wrong, but I'm not sure if I'm on the right track or not.</p> <p>Thanks in advance.</p> </div>

ThinkPHP模板中怎样匹配出相同的字符串?

``` <volist name="arr1" id="vo1"> {$vo1['name']} <!--输出的数据为--> <!-- 小明 小王 小花 --> </volist> <volist name="arr2" id="vo2"> {$vo2['name']} <!--输出的数据为--> <!-- 小明 小李 小王 小小 小花 --> </volist> ``` 以上两个分别是在ThinkPHP模板中volist标签输出的,怎样改为如下方式输出 ``` <volist name="arr3" id="vo3"> <!--输出的数据为--> <!-- 小明,有相同名字 小李,没有相同名字 小王,有相同名字 小小,没有相同名字 小花,有相同名字 --> </volist> ``` 即相同名字输出为相同名字,不相同名字输出为不相同。

PHP / MySQL:SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符

<div class="post-text" itemprop="text"> <p>I have this MySQL table:</p> <pre><code>mysql&gt; select * from members; +-------+-----------+-----------+ | memid | firstname | lastname | +-------+-----------+-----------+ | 1 | billal | begueradj | | 2 | bill | gates | | 3 | steve | jobs | +-------+-----------+-----------+ 3 rows in set (0.00 sec) </code></pre> <p>I have this code:</p> <pre><code>&lt;?php $output = array('error' =&gt; false); $members = array(); try { $db = new PDO('mysql:host=localhost;dbname=bill;charset=utf8', 'root', '' ); } catch(Exception $e) { die('Error in connecting to DB: &lt;br/&gt;'.$e-&gt;getMessage()); } $response = $db-&gt;query('SELECT * FROM members'); while($row = $response-&gt;fetch()){ echo $row['firstname'].' '; echo $row['lastname'].'&lt;br/&gt;'; array_push($members, $row); } $output['members'] = $members; $response-&gt;closeCursor(); $json = json_encode($out); echo $json; // outputs correctly header("Content-type: application/json"); // error here die(); ?&gt; </code></pre> <p>And I am getting this error message when I run the PHP file containing the PHP code above:</p> <blockquote> <p>SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data</p> </blockquote> <p>Why this happens?</p> <p>P.S. Of course, when I comment this line: <code>//header("Content-type: application/json");</code> the error message disappears</p> <p><strong>EDIT: New code version following the comments below:</strong></p> <pre><code>&lt;?php header("Content-type: application/json"); $output = array('error' =&gt; false); $members = array(); try { $db = new PDO('mysql:host=localhost;dbname=bill;charset=utf8', 'root', '' ); } catch(Exception $e) { die('Error in connecting to DB: &lt;br/&gt;'.$e-&gt;getMessage()); } $response = $db-&gt;query('SELECT * FROM members'); while($row = $response-&gt;fetch()){ array_push($members, $row); } $output['members'] = $members; $response-&gt;closeCursor(); $json = json_encode($out); //echo $json; ?&gt; </code></pre> <p>Still getting the same error message</p> </div>

JSON数据如何转换为时间格式?

在THINKPHP模板页中输出{{deadline}} 输出时间, 但是输出的是 1441761664 类似这样的一串数字, 请问该如何转换为时间格式?

TP5后台如何调用前端js的函数?

请教:  在TP5后台,如何调用前端JS的方法? 用 echo 打印出不行吗? TP5 后台:   public  function test(){         // echo "<script type='text/javascript'>test66();</script> ";         echo "  test66()";     } view 页面前端:      function test66() {              alert('test66');             } 这样写,前端view页面 的test66()函数,接收不到TP5 后台echo送过来的信息,请问如何解决? 最后我是这样解决的: view 页面用 ajax 方法,到TP5后台后,用 json方法回传,在ajax的success再次调用JS方法: $(function(){ $('#btnTest').click(function(){ $.ajax({ url: "{:url('admin/test')}", type:"POST", dataType:"script", data:{'id':1 }, success:function (data) { test(); },error:function (data) { } }); }) function test(){ alert('123'); } })

新手求解 java 如何从一串字符串中提取关键字,并存入mysql

我从txt文档中读取了大概几万行的字符串,并存入string数组中,每个数组里的内容大概如下 {"gps":{"type":"gps","Lon":116.34948495921601,"status":"available","Lat":39.9621098626166},"time":"2015-11-11 19:24:57+0800","wifi":[{"ssid":"TP-LINK_514","mac":"88:25:93:69:36:d5","dbm":-43},{"ssid":"LiebaoFree150","mac":"5e:4b:d6:d5:b1:31","dbm":-56},{"ssid":"TP-LINK_5G_514","mac":"88:25:93:69:36:d4","dbm":-51},{"ssid":"10-331","mac":"1c:7e:e5:55:22:b6","dbm":-82},{"ssid":"1%ts","mac":"fc:d7:33:7f:51:d8","dbm":-77},{"ssid":"BUPT-dot1x","mac":"d8:c7:c8:02:a1:19","dbm":-85},{"ssid":"516NB","mac":"fc:d7:33:7f:e9:dc","dbm":-70},{"ssid":"Kevin","mac":"f4:b7:e2:b7:0e:25","dbm":-86},{"ssid":"ChinaNet","mac":"2e:4b:d6:ab:5e:2b","dbm":-62},{"ssid":"517","mac":"fc:d7:33:7f:50:30","dbm":-79},{"ssid":"OP","mac":"36:de:1a:71:82:0c","dbm":-78},{"ssid":"BUPT-1","mac":"d8:c7:c8:02:a1:18","dbm":-89},{"ssid":"360WiFi-414","mac":"8c:a9:82:00:8d:03","dbm":-71},{"ssid":"TP-LINK 414","mac":"80:89:17:fd:8e:82","dbm":-82},{"ssid":"TP-LINK_L","mac":"fc:d7:33:80:08:ea","dbm":-90},{"ssid":"211_Class8_SICE_Building5","mac":"ec:88:8f:43:33:d4","dbm":-91},{"ssid":"TP-LINK_1303","mac":"fc:d7:33:80:09:6c","dbm":-87}],"cell":[{"connected":true,"mnc":"46001","cell_type":"gsm_uni","dbm":-79,"m":"one","networktype":"UMTS","cid":7089899,"lac":41052}]} 请问我该用什么方法,把其中每个{}内的内容提取出来,并按照ssid,mac,dbm 分别存入mysql中 而且每串字符串中,{}的数目不固定 谢谢

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

将一个接口响应时间从2s优化到 200ms以内的一个案例

一、背景 在开发联调阶段发现一个接口的响应时间特别长,经常超时,囧… 本文讲讲是如何定位到性能瓶颈以及修改的思路,将该接口从 2 s 左右优化到 200ms 以内 。 二、步骤 2.1 定位 定位性能瓶颈有两个思路,一个是通过工具去监控,一个是通过经验去猜想。 2.1.1 工具监控 就工具而言,推荐使用 arthas ,用到的是 trace 命令 具体安装步骤很简单,大家自行研究。 我的使用步骤是...

学历低,无法胜任工作,大佬告诉你应该怎么做

微信上收到一位读者小涛的留言,大致的意思是自己只有高中学历,经过培训后找到了一份工作,但很难胜任,考虑要不要辞职找一份他能力可以胜任的实习工作。下面是他留言的一部分内容: 二哥,我是 2016 年高中毕业的,考上了大学但没去成,主要是因为当时家里经济条件不太允许。 打工了三年后想学一门技术,就去培训了。培训的学校比较垃圾,现在非常后悔没去正规一点的机构培训。 去年 11 月份来北京找到了一份工...

JVM内存结构和Java内存模型别再傻傻分不清了

JVM内存结构和Java内存模型都是面试的热点问题,名字看感觉都差不多,网上有些博客也都把这两个概念混着用,实际上他们之间差别还是挺大的。 通俗点说,JVM内存结构是与JVM的内部存储结构相关,而Java内存模型是与多线程编程相关,本文针对这两个总是被混用的概念展开讲解。 JVM内存结构 JVM构成 说到JVM内存结构,就不会只是说内存结构的5个分区,而是会延展到整个JVM相关的问题,所以先了解下

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Google 与微软的浏览器之争

浏览器再现“神仙打架”。整理 | 屠敏头图 | CSDN 下载自东方 IC出品 | CSDN(ID:CSDNnews)从 IE 到 Chrome,再从 Chrome 到 Edge,微软与...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

立即提问
相关内容推荐