Why isn't this working for me:
为什么这不适合我:
$item_id =
"SELECT item_id FROM items WHERE item_id=(SELECT max(item_id) FROM items)";
I'm trying to insert the sql query result into the variable item_id
.
我正在尝试将sql查询结果插入到变量item_id中。
If i write echo"$item_id";
i get the sentence in between the quotes as an output.
如果我写回“$ item_id”;我把引号之间的句子作为输出。
1 个解决方案
#1
2
you must have to do the connection out from the var and you need to do a fetch array try this:
你必须要从var进行连接,你需要做一个获取数组试试这个:
// your connection data //
//您的连接数据//
$link = mysql_connect("localhost", "youruser"); mysql_select_db("yourdb", $link);
$ link = mysql_connect(“localhost”,“youruser”); mysql_select_db(“yourdb”,$ link);
// your select //
//你的选择//
$result = mysql_query("SELECT yourvalue FROM yourtable", $link);
$ result = mysql_query(“SELECT yourvalue FROM yourtable”,$ link);
$row = mysql_fetch_array($result)
$ row = mysql_fetch_array($ result)
your item var
你的项目变种
$item_id = $row ["yourvalue"]
$ item_id = $ row [“yourvalue”]
regards
#1
2
you must have to do the connection out from the var and you need to do a fetch array try this:
你必须要从var进行连接,你需要做一个获取数组试试这个:
// your connection data //
//您的连接数据//
$link = mysql_connect("localhost", "youruser"); mysql_select_db("yourdb", $link);
$ link = mysql_connect(“localhost”,“youruser”); mysql_select_db(“yourdb”,$ link);
// your select //
//你的选择//
$result = mysql_query("SELECT yourvalue FROM yourtable", $link);
$ result = mysql_query(“SELECT yourvalue FROM yourtable”,$ link);
$row = mysql_fetch_array($result)
$ row = mysql_fetch_array($ result)
your item var
你的项目变种
$item_id = $row ["yourvalue"]
$ item_id = $ row [“yourvalue”]
regards