1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 6: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54:
".$_SESSION['ad_id']." LIMIT 1"); $num_rows = mysql_num_rows($result); if( $num_rows == 0 ) { //No ads. greater than the ad_id. It's possible that there are no more ads after this. So start from beginning of ads table $result = mysql_query("SELECT ad_id, ad_title, ad_image FROM ads WHERE is_enabled = 1 ORDER BY ad_id ASC LIMIT 1"); $num_rows = mysql_num_rows($result); if( $num_rows == 0 ) { //No ads. Add some, stranger! } else { //If ad is present, then process it. $row = mysql_fetch_array($result); $_SESSION['ad_id'] = $row['ad_id']; } } else { //If ad is present, then process it & store the id in session. $row = mysql_fetch_array($result); $_SESSION['ad_id'] = $row['ad_id']; } } ?>