json响应mysql获取数据(json response of mysql fetch data)
$sql=mysql_query("select * from school"); while($rows=mysql_fetch_assoc($sql)) print_r($rows)."<br/>"; $response=array(); $info=array(); foreach($rows as $row) { $schoolInfo=array(); $schoolInfo["schoolid"]=$row["schoolid"]; $schoolInfo["schoolname"]=$row["schoolname"]; //$schoolInfo ["grade"] = $row["grade"]; array_push($info,$schoolInfo); } $response['info']=$info; echo json_encode($response);
在这里,我得到了$ response的空白输出。 我使用PHP脚本从mysql获取数据,但我得到空白输出...
$sql=mysql_query("select * from school"); while($rows=mysql_fetch_assoc($sql)) print_r($rows)."<br/>"; $response=array(); $info=array(); foreach($rows as $row) { $schoolInfo=array(); $schoolInfo["schoolid"]=$row["schoolid"]; $schoolInfo["schoolname"]=$row["schoolname"]; //$schoolInfo ["grade"] = $row["grade"]; array_push($info,$schoolInfo); } $response['info']=$info; echo json_encode($response);
here i am getting blank ouput of $response. i am using php script for fetch data from mysql but i am getting blank output...
原文:https://stackoverflow.com/questions/23989408
更新时间:2023-09-21 18:09
最满意答案
请按照以下步骤操作。
创建一个按字符长度分割数据的函数。
CREATE FUNCTION SplitStringByLength ( @inputString varchar(max), @length int ) RETURNS @SplitStrings TABLE( SplitString VARCHAR(50) ) AS BEGIN DECLARE @s VARCHAR(50) WHILE len(@inputString) > 0 BEGIN SET @s = left(@inputString, @length) SET @inputString = right(@inputString, len(@inputString) - @length) INSERT @SplitStrings VALUES (@s) END RETURN END
通过将您的列和字符长度作为输入传递来调用该函数,如下所示。
SELECT ID ,SplitString FROM YourTable CROSS APPLY dbo.SplitStringByLength (YourColumn,4)-- mention the character length to split
Follow the below steps.
Create a function for split your data by character length .
CREATE FUNCTION SplitStringByLength ( @inputString varchar(max), @length int ) RETURNS @SplitStrings TABLE( SplitString VARCHAR(50) ) AS BEGIN DECLARE @s VARCHAR(50) WHILE len(@inputString) > 0 BEGIN SET @s = left(@inputString, @length) SET @inputString = right(@inputString, len(@inputString) - @length) INSERT @SplitStrings VALUES (@s) END RETURN END
call the function by passing your column and length of characters as input like below.
SELECT ID ,SplitString FROM YourTable CROSS APPLY dbo.SplitStringByLength (YourColumn,4)-- mention the character length to split
相关问答
更多-
string.split('$$TEXT$$') ? >>> a="1.MATCHES$$TEXT$$STRING" >>> a.split("$$TEXT$$") ['1.MATCHES', 'STRING'] >>> a="2.MATCHES $$TEXT$$ STRING" >>> a.split("$$TEXT$$") ['2.MATCHES ', ' STRING'] 和: >>> [x.strip() for x in "2.MATCHES $$TEXT$$ STRING".split("$ ...
-
或者: 使用\uXXXX表单在字符串文字中指定符号: str.split("\u0007") 将char 7转换为String: str.split(Character.toString((char) 7)); Ideone演示 Either: Use the \uXXXX form to specify the symbol in the string literal: str.split("\u0007") Convert a char 7 to a String: str.split(Chara ...
-
使用外观。 String[] splitted = text.split("((?<=foo)(?=.)|(?<=.)(?=foo))") Use lookarounds. String[] splitted = text.split("((?<=foo)(?=.)|(?<=.)(?=foo))")
-
简单的方法 只需使用string-right-trim : (string-right-trim " ,.;!?/" s) 你的错误 如果将空字符串传递给del-delimiter-at-end ,则会将-1作为第二个参数传递给char 。 你的守则 没有理由这样做(eq (delimiterp ...) nil) ; 只需使用(delimiterp ...)代替(并切换子句!) 当你只有两个条款并且每个只有一个表格时,使用if和not cond是模式惯用语。 你subseq递归方式调用subseq ,这 ...
-
如何(容易)在Ruby中将字符串拆分为长度和分隔符(How to (easily) split string in Ruby with length and also delimiter)[2022-11-14]
你可以使用正则表达式: 至少width-2字符的非贪婪重复 接着是} 其次是a或a ] 。 data = "[{a:1,b:2,c:3,d:4},{a:5,b:6,c:7,d:8},{a:9,b:10,c:11,d:12},{a:13,b:14,c:15,d:16}]" def split_data_with_min_width(text, width) pattern = / ( # capturing group for split .{#{wi ... -
最少使用unicode分隔符(Least used unicode delimiter)[2022-12-22]
如果这仅用于内部表示(即不用于交换和存储),则可以使用非字符代码点,例如U + FFFF。 例如,Java使用它作为完成CharacterIterator的信号 。 If this is only for an internal representation (i.e. not for interchange and storage), then you can use a non-character code point such as U+FFFF. Java uses that as the sign ... -
请按照以下步骤操作。 创建一个按字符长度分割数据的函数。 CREATE FUNCTION SplitStringByLength ( @inputString varchar(max), @length int ) RETURNS @SplitStrings TABLE( SplitString VARCHAR(50) ) AS BEGIN DECLARE @s VARCHAR(50) WHILE len(@inputString) > 0 BEGIN SET @s = ...
-
您可以使用正则表达式拆分为两个字符的组: Dim parts = Regex.Matches(s, ".{2}").Cast(Of Match)().Select(Function(m) m.Value) 演示: http : //ideone.com/ZVL2a (C#) You can use a regular expression to split into two-character groups: Dim parts = Regex.Matches(s, ".{2}").Cast(Of Mat ...
-
用空行分隔符拆分(Split with empty line delimiter)[2022-08-31]
注意不同操作系统的行结束约定 ! Windows:CRLF( \r\n ) Linux和其他Unices:LF( \n ) 旧Mac:CR( \r ) 您可能失败了,因为您要查找的双换行符位于Windows编码的文本文件中,并且显示为\r\n\r\n ,而不是\n\n 。 repr()函数会告诉您确定行结尾是什么: >>> mystring = #[[a line of your file]] >>> repr(mystring) "'\\nmulti\\nline\\nstring '" 你确定你不只是 ... -
引用的问题解决为wont-fix。 这意味着他们没有看到这个问题的必要性。 但我想建议您使用像这样的解决方法策略来实现您自己的Tokenizer类(可能扩展AbstractLineTokenizer )。 The referenced issue is resolved as wont-fix. This means they don't see the necessity of this issue. But I guess you are recommended to implement your ow ...