Tools, FAQ, Tutorials:
Looping through Returning Rows from a Query in PHP
How To Query Tables and Loop through the Returning Rows in PHP?
✍: FYIcenter.com
The best way to query tables and loop through the returning rows is to run the SELECT statement with the catch the mysql_query() function, catch the returning object as a result set, and loop through the result with the mysql_fetch_assoc() function in a while loop as shown in the following sample PHP script:
<?php include "mysql_connection.php"; $sql = "SELECT id, url, time FROM fyi_links"; $rs = mysql_query($sql, $con); while ($row = mysql_fetch_assoc($rs)) { print($row['id'].", ".$row['url'].", ".$row['time']."\n"); } mysql_free_result($rs); mysql_close($con); ?>
Using mysql_fetch_assoc() is better than other fetch functions, because it allows you to access field values by field names. If you run this script, you will see all rows from the fyi_links table are printed on the screen:
101, dev.fyicenter.com, 2006-02-26 22:29:02 102, dba.fyicenter.com, 2006-02-26 22:29:02 1101, dev.fyicenter.com, 2006-02-26 22:29:02 1102, dba.fyicenter.com, 2006-02-26 22:29:02
⇒ Updating Existing Rows in PHP
⇐ What Is a Result Set Object in PHP
2016-10-19, 1707🔥, 0💬
Popular Posts:
How to dump (or encode, serialize) a Python object into a JSON string using json.dumps()? The json.d...
How to use the "forward-request" Policy Statement to call the backend service for an Azure API servi...
How to use the "set-backend-service" Policy Statement for an Azure API service operation? The "set-b...
How To Loop through an Array without Using "foreach" in PHP? PHP offers the following functions to a...
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...