Tuesday 15 March 2011

php - mysqli_fetch_array returning only one result -



php - mysqli_fetch_array returning only one result -

i'm trying create very, simple query of little mysql database, using next code (with appropriate values in $host, etc.):

$connection = mysqli_connect($host, $user_name, $password, $database); if (mysqli_connect_errno($connection)) { echo "failed connect mysql: " . mysqli_connect_error(); } $result = mysqli_query($connection, "select university universities_alpha"); $row = mysqli_fetch_array($result); echo print_r($result); echo '<br><br>'; echo print_r($row); mysqli_close($connection);

as can see, printed out results in human-readable way, yielding:

mysqli_result object ( [current_field] => 0 [field_count] => 1 [lengths] => array ( [0] => 19 ) [num_rows] => 9 [type] => 0 ) 1 array ( [0] => arizona state univ. [university] => arizona state univ. ) 1

there few illustration universities in column, i'm not sure i'm doing wrong.

mysqli_fetch_array works pointers each time it's called

imagine following

$result = mysqli_query($connection, "select university universities_alpha"); $row = mysqli_fetch_array($result); // first row $row = mysqli_fetch_array($result); // it's sec row $row = mysqli_fetch_array($result); // 3rd row

to display info way want to, suggest following

$rows = array(); $result = mysqli_query($connection, "select university universities_alpha"); while($row = mysqli_fetch_array($result)) $rows[] = $row; print_r($rows);

php mysql

No comments:

Post a Comment