小编hun*_*ter的帖子

如何在php中将字符串转换为数组

如何在PHP中转换数组中的字符串即

 $str="this is string";

应该是这样的

 arr[0]=this
      arr[1]=is
      arr[2]=string 

str_split($str, 3);
将字符串拆分为3个字符的单词,但我想在数组中的空格后转换字符串.

php

32
推荐指数
5
解决办法
18万
查看次数

第1行第2行出错:文档末尾的额外内容

当我使用下面的代码并在本地解析xml时,它可以正常工作,但是当在服务器上传相同的脚本时,它会显示错误.

注:我检索到的$lng,并$lat从查询字符串,并将其在本地工作正常.

$lng=$_GET['lng'];
$lat=$_GET['lat'];
$conn=new LoginSystem();
$conn->connect();
$dom = new DOMDocument("1.0");

$query="select catch_id,catch_details,image from mycatch where longitude='$lng' AND latitude='$lat'";
$result = mysql_query($query);

if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("mycatch");
  $node = $dom->appendChild($node);
foreach ($row as $fieldname => $fieldvalue) {
      $child = $dom->createElement($fieldname);
    $child = $node->appendChild($child);
    $value = $dom->createTextNode($fieldvalue);
    $value = $child->appendChild($value);
  }
}

$conn->disconnect();
$xml_string …
Run Code Online (Sandbox Code Playgroud)

php xml

23
推荐指数
4
解决办法
12万
查看次数

如何在php/mysql中使用事务

我正在使用php/mysql.我知道mysql中的事务但不能在我的脚本中使用.下面是我的脚本我怎么能在我的code.ie BEGIN,ROLLBACK,COMMIT中使用php事务

foreach($json_a['shop'] as $jsondata=>$json)
{
if($json['category']==='product')
{
$name_product=$json['name'];
$query1="insert into product(id,name,user_id)values('','" . mysql_real_escape_string($name_product). "','1')";

$result1=mysql_query($query1) or die("error in query".mysql_errno());
//echo "success...!";
$product++;
}
else
if($json['category']==='order')
{
$name_order=$json['name'];
$query2="insert into order(id,name,user_id)values('','" . mysql_real_escape_string($name_order). "','1')";

$result2=mysql_query($query2) or die("error in query".mysql_errno());
$order++;
}
else
if($json['category']==='sale')
{
$name_sale=$json['name'];
$query3="insert into sale(id,name,user_id)values('','" . mysql_real_escape_string($name_sale). "','1')";

$result3=mysql_query($query3) or die("error in query".mysql_errno());
$sale++;
}
}
Run Code Online (Sandbox Code Playgroud)

php mysql

8
推荐指数
2
解决办法
7898
查看次数

如何解析json到php

我有一个从数据库中检索到的json数据,即

$result=array();
$query="SELECT * FROM fish";
$result1 = mysql_query($query, $conn);
while ($table = mysql_fetch_array($result1, MYSQL_ASSOC)){
   $result[]=$table;
}
   echo json_encode($result);
Run Code Online (Sandbox Code Playgroud) 这给了我结果
[{"fish_id":"1","name":"first fish update","info":"this is my first fish update","image":"http:\/\/www.localhost\/cafe\/pics\/logout (1).gif"}]

但是当我调用这个json数据时,从另一个页面,即

$input = file_get_contents("http://localhost/fish/fish-json.php");
$json=json_decode($input);
echo $json->fish_id;

它给了我错误

Notice: Trying to get property of non-object in /var/www/fish/json-to-php.php on line 13 Call Stack: 0.0005 318764 1. {main}() /var/www/fish/json-to-php.php:0

php

2
推荐指数
1
解决办法
6786
查看次数

这个查询有什么问题

当我将记录插入mysql时,它给我错误

$sql = "insert into fish (fish_id,common_name,scientific_name,family,range,habitate,adult_size,identification,how_to_fish,image) values ('$com_name','$scientific_name','$family','$range','$habitate','$adult_size','$identification','$how_to_fish','$TARGET_PATH')";
Run Code Online (Sandbox Code Playgroud)

错误是

无法将数据插入数据库:您的SQL语法中有错误; 检查与MySQL服务器版本对应的手册,以便range,habitate,adult_size,identification,how_to_fish,image) values ('Suwannee Ba在第1行的' ' 附近使用正确的语法

当我转储查询时,它显示所有字段都是正确的.

string(737) "insert into fish (catch_id,common_name,scientific_name,family,range,habitate,adult_size,identification,
how_to_fish,image) values ('','Suwannee Bass','Micropterus notius','Centrarchidae (Sunfish)','United States (Florida, Georgia)',
'Freshwater: found in Suwannee and Ochlockonee river drainages of Florida and Georgia.',
'Up to 12 oz (.34 kg).','The smallest of the Black Bass; brown with dark markings along back and sides. Adult male has blue cheeks, breast, and belly.',
'Natural or artificial bait such as spinners, …
Run Code Online (Sandbox Code Playgroud)

php mysql

0
推荐指数
1
解决办法
72
查看次数

#1054 - Unknown column 'de15a674d1252f6565a65756ebfa97e8e1e58c9c' in 'where clause'

i have two tables

CREATE TABLE IF NOT EXISTS `user` (
  `user_id` int(20) NOT NULL AUTO_INCREMENT,
  `ud_id` varchar(50) NOT NULL,
  `name` text NOT NULL,
  `password` text NOT NULL,
  `email` varchar(200) NOT NULL,
  `image` varchar(150) NOT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB

and mycatch table is

CREATE TABLE IF NOT EXISTS `mycatch` (
  `catch_id` int(11) NOT NULL AUTO_INCREMENT,
  `catch_name` text NOT NULL,
  `catch_details` text NOT NULL,
  `longitude` float(10,6) NOT NULL,
  `latitude` float(10,6) NOT NULL,
  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON …

mysql mysql-error-1054

-1
推荐指数
1
解决办法
6040
查看次数

标签 统计

php ×5

mysql ×3

mysql-error-1054 ×1

xml ×1