PHP MSSQL Query a problem (ask)
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. PHP MS? SQL Select
Share to:
------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