Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Query Tables and Loop through the Returning Rows
How To Query Tables and Loop through the Returning Rows? - PHP Script Tips - Working with MySQL Database
✍: 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
2007-04-19, 5132👍, 0💬
Popular Posts:
How To Select Some Rows from a Table? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY If yo...
Can Java object be locked down for exclusive use by a given thread? Yes. You can lock an object by p...
What Are Named Parameters? - Oracle DBA FAQ - Creating Your Own PL/SQL Procedures and Functions Name...
What is Traceability Matrix? Traceability Matrix is one of the document will prepare by QA.To make s...
How To Retrieve Input Values for Checkboxes Properly? - PHP Script Tips - Processing Web Forms If mu...