Jump to content

sql query isn't pulling what it should


CecilDL

Recommended Posts

My php code:

<?php 
	$sql = "SELECT movieid FROM showtimes WHERE curdate() BETWEEN st AND en";
	$query = mysql_query($sql,$db);
	$output = mysql_fetch_array($query, MYSQL_NUM);
	$takenmovies = implode(",",$output);
?>

When I run that sql statement on phpmyadmin, I get 4 rows.

When it's run in my page, I get 1 result; always just the first row.

 

st is startdate, and en is enddate for my date range.

 

WHY???????

 

sql table, with data in it:

CREATE TABLE `showtimes` (
  `id` tinyint(10) NOT NULL auto_increment,
  `st` date NOT NULL,
  `en` date NOT NULL,
  `movieid` tinyint(10) NOT NULL,
  `times` text collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;

INSERT INTO `showtimes` VALUES (1, '2007-11-02', '2007-11-08', 2, '1:05,3:50,7:00,9:50');
INSERT INTO `showtimes` VALUES (2, '2007-11-02', '2007-11-08', 3, '1:15,4:10');
INSERT INTO `showtimes` VALUES (3, '2007-11-02', '2007-11-08', 9, '1:25,6:45');
INSERT INTO `showtimes` VALUES (4, '2007-11-02', '2007-11-08', 12, '9:45');

 

(hope I've given enough information)

 

Thankyou for reading.

Link to comment
https://forums.phpfreaks.com/topic/76596-sql-query-isnt-pulling-what-it-should/
Share on other sites

$sql = "SELECT movieid FROM showtimes WHERE curdate() BETWEEN st AND en";
$query = mysql_query($sql,$db);
while($output = mysql_fetch_array($query, MYSQL_NUM)){
  $takenmovies[]= $output;
}
print_r($takenmovies);
//$takenmovies = implode(",",$output);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.