PHP MS SQL Select
Get all values for the entire column, and convert to a 2-D array.
function GetAll ($sql) {
$query =mssql_query ($sql);
if ($query) {
$temp =array ();
while ($res =mssql_fetch_assoc ($query)) {
$temp []= $res;
}
return $temp;
}
else{
return false;
}
}
$result = "Select ZDMC from QX WHERE jsid=9 and tcmc= ' $DITCBO ' and kj=1";
$arr =getall ($result);
Convert a two-dimensional array to a string separated by a single and comma
for ($i =0; $i
$array [] = $arr [$i] ["ZDMC"];
}
$r = "'". Implode ("', '", $array). "'";
Use this string to query the table
$result 2 = Mssql_query ("Select $r from $SJB WHERE id= ' $bh '");
$row = Mssql_fetch_array ($result 2);
Print_r ($row)
The results are displayed as
Garbled is because this is read is Mmsql GBK code, used when I will be converted, but now read in the content is not correct
New handwriting, begging for help, bro.
Reply to discussion (solution)
$r = ' ['. Implode ("],[", $array). '] ';
Since the $r is a list of fields, wouldn't it be a string to enclose it in single quotation marks?
Look, your field names are mostly in Chinese. This requires the field name to be surrounded by [] and you can see it in SQL Server Manager
Do you mean to enclose the field names in brackets and separate them with commas?
I copied the error you gave me.
You give the wrong message when you make an error
function GetAll ($sql) {
$query =mssql_query ($sql);
if ($query) {
$temp =array ();
while ($res =mssql_fetch_assoc ($query)) {
$temp []= $res;
}
return $temp;
}
else{
return false;
}
}
$result = "Select ZDMC from QX WHERE jsid=9 and tcmc= ' $DITCBO ' and kj=1";
$arr =getall ($result);
for ($i =0; $i
$array [] = $arr [$i] ["ZDMC"];
}
$r = ' ['. Implode ("],[", $array). '] ';
$r = "'". Implode (",", $array). "'";
$result 2 = Mssql_query ("Select from $SJB WHERE id= ' $bh '");
$row = Mssql_fetch_array ($result 2);
Print_r ($row)
I'm sorry, I'll help you see.
Who can see your mess of stickers?
$r = ' ['. Implode ("],[", $array). '] ';
echo Convert2utf8 ($R);
Echo GetType ($R);
Show "UTF8" as Chinese results
Then, with the original GBK code, the table is tested to read the normal, do not know where the problem is AH!
$r = ' ['. Implode ("],[", $array). '] ';
$result 2 = Mssql_query ("Select $r from $SJB WHERE id= ' $bh '");
$row = Mssql_fetch_array ($result 2);
Print_r ($row)
Where did the string in the first sheet come from?
It's better to deal with Chinese mssq or GBK code.
echo a bit GetType ($R);
If this is different, then you have to think of another way.