Probling getting rows from DB

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Locked
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Probling getting rows from DB

Post 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...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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;
  }
}

.....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"Original" thread here: viewtopic.php?t=32252
Locked