Not getting results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Not getting results

Post by thiscatis »

Code: Select all

<?php
	   
 
 $result = mysql_query("SELECT * FROM ingeschreven ORDER BY id DESC ") or die(mysql_error());  
  while($row = mysql_fetch_array( $result )) {
	  $naam = $row['naam'] . " ";
}
while($naam=mysql_fetch_row($result))
{
  $i=0;
  while ($i < mysql_num_fields($result))
  {
    $field_name=mysql_fetch_field($result, $i);
    echo $naam[$i] . " ";  //Display all the fields on one line
    $i++;
  }

}



	    ?>
I'm trying to get all the names from a table called "ingeschreven" and the name field is named "naam"...
klarinetking
Forum Commoner
Posts: 59
Joined: Mon Jul 24, 2006 9:43 am

Post by klarinetking »

Hi,

You're using mysql_fetch_array, which returns numbered fields. If you want to be able to use associative arrays, use mysql_fetch_assoc.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Hehe try using this:

Code: Select all

<?php
          
 
 $result = mysql_query("SELECT * FROM ingeschreven ORDER BY id DESC ") or die(mysql_error()); 
  while($row = mysql_fetch_array( $result )) {
          $naam .= $row['naam'] . " ";
} 

echo $naam;
?>
@klarinetking http://php.net/manual/en/function.mysql-fetch-array.php
Post Reply