Possible Duplicate:
PHP SQL, query returns only one row of data
A friend of mine is asked me to do some coding. He created a MySQL database with columns “gameName” (VARCHAR) and “releaseDate” (date). He needs to fetch and show the game names from “gameName” which are released before current date.
Here I have used MySQL’s CURDATE() function to filter out already released games. But the problem is I have to write an echo line for each results. It’s bad programming and the logic behind that is very bad.
<?php
$mysql_host="host_name";
$mysql_username="db_user";
$mysql_password="db_password";
$mysql_database="db_name";
$mysql_table="table_name";
mysql_connect("host_name", "db_user", "db_password") or die("YOLO");
mysql_select_db("db_name") or die("YOLO");
$sql = mysql_query("SELECT gameName FROM table_name WHERE CURDATE() > releaseDate");
$result = mysql_fetch_row($sql);
echo $result[0];
echo $result[1];
echo $result[2];
// and so on...?
?>
Result: Only one record showed up.
PDO example,