English 中文(简体)
PHP 爆炸功能引发问题
原标题:PHP explode function causing issue
  • 时间:2012-05-23 01:05:49
  •  标签:
  • php
  • mysql

我试图为我的网站创建一种Twitter样式。 每当下面的脚本在数据库中添加“ 阵列 ”, 而不是你试图跟踪的人的用户代号。 Dunno 如何修复它 。

<?
session_start();
# Connect to the mysql database
include_once "library/connect_to_mysql.php"; 

if(isSet($_POST[ mem ])){

#filter everything but numbers for security
$mem1 = preg_replace( #[^0-9]#i ,   , $_POST[ mem ]); 
$mem2 = $mem1;

#Decode the Session IDX variable and extract the user s ID from it
$decryptedID = base64_decode($_SESSION[ idx ]);
$id_array = explode("p3h9xfn8sq03hs2234", $decryptedID);
$my_id = $id_array[1];

$sql = mysql_query("SELECT following_array FROM Members WHERE id= $my_id  LIMIT 1"); 

while($row = mysql_fetch_array($sql)) { 
$following = $row["following_array"]; 
}

$followArry1 = explode( , , $following);

if (in_array($mem1, $followArry1)) {

exit(); 
}

if ($followArry1 != "") { 

$followArry2 = "$followArry1,$mem2"; 

} else { 

$followArry2 = "$mem2"; 
}

$UpdateArray = mysql_query("UPDATE Members SET following_array = $followArry2  WHERE id= $my_id ") or die (mysql_error());

exit();

}else{

exit();
}

?>

爆炸(arry,2)

任何感谢的帮助

/////// Updated Code ////////////////////

$followArry1 = explode(",", $following);

if (in_array($mem1, $followArry1)) { exit(); }

if ($followArry1 != "") { 

    $followArry1 = implode( , , $followArry1 + array($mem1)); 

} else { 

    $followArry1 = $mem1; 
}

$UpdateArray = mysql_query("UPDATE myMembers SET following_array = $followArry1  WHERE id= $my_id ") or die (mysql_error());
最佳回答

我也认为问题在于将$mem变量加到$folfyArry1 阵列中。

试试这个代码...

if ($followArry1 != "") { 
    $followArry1[] = $mem1;
    $followArry1 = implode( , , $followArry1); 

} else { 

    $followArry1 = $mem1; 
}
问题回答

$followArry1是一个数组,转换成字符串显示“Array ”。

见此证明(现场演示:http://ideone.com/tMndH ):

$followArry1 = array( a ,  b ,  c ); // just an array
$result = "$followArry1"; // it is now string containing "Array"

尝试以下(例如:http://ideone.com/h5ilz ):

$followArry1 = array( a ,  b ,  c );
$mem =  d ;
$followArry2 = implode( , , $followArry1 + array($mem));




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签