$row=mysql_fetch_array($result); only returns even rows
We have this code:
$rowArray;
$rowID = 1;
$query = "SELECT idCentros FROM centros";
$result = mysql_query($query);
$numrows=mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
$rowArray[$rowID] = $row['idCentros'];
$rowID = $rowID +1;
}
$numrows returns 4 (the rows we have in that table)...but for an unkown reason the loop starts retrieving the 2º row next it retrieves the 4º row and then it ends the loop ($row =false). As 开发者_开发技巧we understand this is generic code and the table definition is like this:
column idcentros int(11) pk notnull autoincremental
column nombre mediumtext
What could be happening? Thanks in advance...
try this:
$query = "SELECT idCentros FROM centros";
$result = mysql_query($query);
$numrows=mysql_num_rows($result);
$rowArray = array();
while($row = mysql_fetch_array($result))
{
array_push($rowArray,$row);
}
I don't see why the above code shouldn't work, but ... here's how I would do it:
$rowArray = array();
$query = "SELECT idCentros FROM centros";
$result = mysql_query($query);
$numrows=mysql_num_rows($result);
while($row = mysql_fetch_row($result)){
$rowArray[] = $row[0];
}
... I believe you have $rowID
set to 1
just for visualisation later, but it's pointless - you should use HTML lists or some $counter++
variable for the output.
精彩评论