php/mysql query problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

php/mysql query problem

Post by someguyhere »

In the code below, I get a null value. If I echo $month_start and $upcoming_events_end, I get 2011-01-01 and 2011-01-31, so it appears that the correct data is being passed. Any idea what might be wrong here?

Code: Select all

			$month_start = date('Y') . '-' . date('m') . '-01';
			$query = "SELECT * FROM wp_calendar WHERE event_category = '4' BETWEEN '$month_start' AND '$upcoming_events_end'";
			$result = mysqli_query($mysqli, $query) or die(mysqli_error());
			$cal_banner = mysqli_fetch_row($result);
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: php/mysql querry problem

Post by John Cartwright »

Check mysqli_num_rows($result) to see if the query returned any results.

What happens if you run the query directly through mysql or phpmyadmin? Do you get rows returned?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php/mysql query problem

Post by AbraCadaver »

$query = "SELECT * FROM wp_calendar WHERE event_category = '4' AND something BETWEEN '$month_start' AND '$upcoming_events_end'";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: php/mysql query problem

Post by someguyhere »

Thanks - that helped me find my problem :)
Post Reply