Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i can't get multiple rows into array from mysql database?

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?

<?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 } ?>

2 Answers

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:

SELECT id AS wid FROM mywishlist
WHERE pid IN ($pid)
like image 163
dfsq Avatar answered Nov 28 '25 08:11

dfsq


your query is wrong, use this query

$result=mysql_query("SELECT id AS wid FROM mywishlist where pid IN($pid) ") 
like image 44
Yogesh Suthar Avatar answered Nov 28 '25 07:11

Yogesh Suthar