Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- How to blend adsense inside your post?
- Formatting my post
- PHP: add a download as pdf file button in report page
- Notepad++ - Add C++ compiler
- PHP connect IBM db2 database in XAMPP
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Sweet Alert JS library - beautiful replacement of JavaScript Alert
- ActionScript 3.0 demo: create a falling snow in flash CS6
Tuesday, March 19, 2013
check if mysql query returns empty in PHP
We can use PHP function mysql_num_rows to check if mysql query returns empty.
Example code:
$sql = "SELECT * FROM cesei_member_extra WHERE member_id = $id";
$result = mysql_query($sql, $db);
if ($result) {
if (mysql_num_rows($result) == 0) {
echo "No result returns"; }
else {
echo mysql_num_rows($result).' rows returned';
}
}
else{
echo "Query error";
}
If the query is not empty, we can use mysql_fetch_assoc to get the result
$enrollment_list = Array();
while($row = mysql_fetch_assoc($result)){
$enrollment_list[] = $row['member_id'];
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment