Difference between revisions of "PHP:Read From a Database"

From Progzoo
Jump to: navigation, search
 
Line 10: Line 10:
 
   die($dbh->connect_error);
 
   die($dbh->connect_error);
 
}
 
}
$bigPop = 1000000;
+
$bigPop = 100000000;
 
$query = $dbh->prepare(
 
$query = $dbh->prepare(
 
"SELECT name, population
 
"SELECT name, population
Line 20: Line 20:
 
$query->bind_result($name,$pop);
 
$query->bind_result($name,$pop);
 
while ($query->fetch()){
 
while ($query->fetch()){
   echo "$name\t$pop\n";
+
   printf("%-20s %10d\n",$name,$pop);
 
}
 
}
 
$query->close();
 
$query->close();
 
$dbh->close()
 
$dbh->close()
 
?>
 
?>
 +
 
]]></prog>
 
]]></prog>
 
You can access other columns from the <code>bbc</code> table.
 
You can access other columns from the <code>bbc</code> table.

Latest revision as of 11:32, 12 June 2017

Read the name and population for each country with a population of more than 1000000000.

You can access other columns from the bbc table. The columns are name region area population and gdp.

[Font] [Default] [Show] [Resize] [History] [Profile]

php:PHP and MySQL