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:
name | age |
---|---|
Timmy Mellowman | 23 |
Sandy Smith | 21 |
Bobby Wallace | 15 |
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
Sandy Smith - 21
Bobby Wallace - 15
0 comments:
Post a Comment