|
Fetch MySQL RowFetch (retrieve) a specific MySQL row and display it in a simple table. This week we are going to work with a common use of PHP and MySQL, fetching results from MySQL and displaying them We will first take a look at the code and then explain it in depth $sql_link = mysql_connect('localhost', 'user', 'pass');
That is the code, now on to the explanation phase. $sql_link = mysql_connect('localhost', 'user', 'pass');
The first line is used to connect with a MySQL database and the second simply connects to a database. You would input your specific server connection info, which can be obtained by your admin/host. $book_id = $_GET['bid']; $_GET is used to pull in the book id $result = mysql_query($query); Actually execute the sql and grab are resultset print "<table>"; // opening of the table print "output" an opening to the table while($row = mysql_fetch_array($result)) {
Loop through the results and print them print "<tr><td>" . $row['b_name'] . "</td><td>" Display the data in a little "non-formatted" table.</table> print "</table>"; Close the table mysql_close($sql_link); Finally close the mysql connection |