i can't get multiple rows into array from mysql database? i have code but it is not working or not showing all rows when i echo into textbox?
我无法从mysql数据库将多行转换成数组?我有代码,但是当我返回文本框时它没有显示所有行?
<?php
if(is_array($_SESSION['pid']))
{
$pid = join(',',$_SESSION['pid']);
$result=mysql_query("SELECT id AS wid FROM mywishlist where pid='$pid'")
or die("Id Problem"."<br/><br/>".mysql_error());
$results= array();
$i=0; // add the new line
while($row=mysql_fetch_array($result)){
$results[$i] = $row['wid'];
$i++;
}
$results;
}
$max=count($results);
for($j=0; $j<$max; $j++)
{
?>
<input type="text" name="wid[]" value="<?php echo $results[$j]; ?>" />
<?php } ?>
3 个解决方案
#1
2
The line join(',',$_SESSION['pid'])
makes me think that you want to select multiple rows by their pid
. Try to make use of IN
operator:
行连接('、'、$_SESSION['pid'])使我认为您希望通过它们的pid选择多个行。尝试利用IN算子:
SELECT id AS wid FROM mywishlist
WHERE pid IN ($pid)
#2
1
Try
试一试
$results= array();
while($row=mysql_fetch_array($result))
{
$results[] = $row['wid'];
}
And For Loop as.
和For循环。
$max = count($results);
for($j=0; $j<$max; $j++)
{
?>
<input type="text" name="wid[]" value="<?php echo $results[$j]; ?>" />
<?php
}
?>
#3
1
your query is wrong, use this query
您的查询是错误的,请使用此查询
$result=mysql_query("SELECT id AS wid FROM mywishlist where pid IN($pid) ")
#1
2
The line join(',',$_SESSION['pid'])
makes me think that you want to select multiple rows by their pid
. Try to make use of IN
operator:
行连接('、'、$_SESSION['pid'])使我认为您希望通过它们的pid选择多个行。尝试利用IN算子:
SELECT id AS wid FROM mywishlist
WHERE pid IN ($pid)
#2
1
Try
试一试
$results= array();
while($row=mysql_fetch_array($result))
{
$results[] = $row['wid'];
}
And For Loop as.
和For循环。
$max = count($results);
for($j=0; $j<$max; $j++)
{
?>
<input type="text" name="wid[]" value="<?php echo $results[$j]; ?>" />
<?php
}
?>
#3
1
your query is wrong, use this query
您的查询是错误的,请使用此查询
$result=mysql_query("SELECT id AS wid FROM mywishlist where pid IN($pid) ")