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
- Notepad++ - Add C++ compiler
- Install PHPMailer 5.2.4 and use smtp gmail
- Wayback Machine - see archived versions of web pages across time
- Set up a child account and set screen time limit in Windows 8
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHP ibm_db2 extension in Linux (redHat)
- PHP: add a download as pdf file button in report page
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