Fetch Data by Array using Php


mysql fetch array
MySQL doesn't have a Fetch Array work. mysql_fetch_array is really a PHP work that enables you to get to information put away in the outcome came back from a fruitful mysql_query. On the off chance that you have been hopping around our MySQL Tutorial then you would have just observed this capacity flying up everywhere.


mysql_fetch_array: why use it?.

PHP and MySQL Code:

<?php
$result = mysql_query("SELECT * FROM example");
?>

row of data

xample MySQL Table:

nameage
Timmy Mellowman23
Sandy Smith21
Bobby Wallace15


getting a row of data using mysql_fetch_array

PHP and MySQL Code:

<?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 
  
$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['name']. " - ". $row['age'];
?>

Display:

Timmy Mellowman - 23

fetch array while loop

PHP and MySQL Code:

<?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 
  
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
 echo $row['name']. " - ". $row['age'];
 echo "<br />";
}
?>

Display:

Timmy Mellowman - 23
Sandy Smith - 21
Bobby Wallace - 15

Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment