你好我现在有这个密码
#issue query
$query1 = "SELECT ITEM_NAME FROM items_to_buy
ORDER BY ITEM_NAME ASC";
$result1 = mysql_query ($query1)
or die ("Cannot execute query");
$itemnamesdata = array();
while ($row = mysql_fetch_array($result1))
{
$itemnamesdata[] = $row[0];
}
for ($n = 0; $n < count($itemnamesdata); $n++)
{
$Line = each ($itemnamesdata);
print ("$Line[value].<p>\n");
}
mysql_free_result ($result);
它可以工作,并给我列中的所有项:item_name
像这样打印出来:
Widescreen VA
460W PSU
Router
DSLR Body
Winter Jacket
Smartphone
17-50MM F/2.8 LENS
Colormeter
现在如何将每个结果放入它自己的唯一变量中?
我希望能像这样分别称呼他们:
$value1 = Widescreen VA
$value2 = 460W PSU
$value3 = Router
$value4 = DSLR Body
$value5 = Winter Jacket
$value6 = Smartphone
$value7 = 17-50MM F/2.8 LENS
$value8 = Colormeter
提前谢谢!!!
最佳答案
在循环本身中,您可以执行以下操作:
$arr = array();
for ($n = 0; $n < count($itemnamesdata); $n++){
$Line = each ($itemnamesdata);
print ("$Line[value].<p>\n");
$arr['var_' . $n] = $Line['value'];
}
extract($arr);