Page 1 of 1

Probling getting rows from DB

Posted: Mon Apr 04, 2005 6:01 am
by Perfidus
After a night with no sleeping at all, I'm starting to make some stupid mistakes, I'm trying to store the arrays ($row) coming from database in a new longer array called $despdef:

Code: Select all

$desp = mysql_num_rows($rs);
if(($desp<15)&&($desp>0)){
$desp2=15;
for($f=0;$f<$desp;$f++){
while ($row = mysql_fetch_array($rs)){
$despdef[$f]=$row;
}}
for($d=$desp;$d<$desp2;$d++){
$despdef[$d]=0;
}}
The fact is that I only get 1 row from DB, I know is obvious,
but I'm too
o
o
o
tired...

Posted: Mon Apr 04, 2005 6:32 am
by timvw
you have a for loop that would iterate through the resultset...

but then, in every loop, you have a while loop that iterates through that resultset...

and in that while loop, you always assign something different to $def[0].

rewrite like

Code: Select all

....

for ($f = 0; $f < $desp; ++$f)
{
  $row = mysql_fetch_array($rs);
  if ($row)
  {
    $despdef[$f] = $row;
  }
}

.....

Posted: Mon Apr 04, 2005 9:48 am
by feyd
"Original" thread here: viewtopic.php?t=32252