The Little Guy Posted May 12, 2009 Share Posted May 12, 2009 Hey, When I call news_results, and echo gettype the $sql is null, why is that? I thought I should get a resource instead. Thanks for the help! <?php class News{ private $sql; public function __construct($dir = 'ASC', $count = 3){ $sql = mysql_query("SELECT * FROM news ORDER BY id $dir LIMIT $count") or die(mysql_error()); } public function news_results(){ echo gettype($sql); return mysql_fetch_array($sql); } } ?> I am using the above like this: <?php $news = new News(); while($row = $news->news_results()){ echo $row['subject']; } ?> Link to comment https://forums.phpfreaks.com/topic/157885-solved-gettype-is-null/ Share on other sites More sharing options...
Maq Posted May 13, 2009 Share Posted May 13, 2009 Do you mind sharing the correct code in case someone else runs into a similar issue? Link to comment https://forums.phpfreaks.com/topic/157885-solved-gettype-is-null/#findComment-832987 Share on other sites More sharing options...
The Little Guy Posted May 13, 2009 Author Share Posted May 13, 2009 sure... This line: $sql = mysql_query("SELECT * FROM news ORDER BY id $dir LIMIT $count") or die(mysql_error()); Should be: $this->sql = mysql_query("SELECT * FROM news ORDER BY id $dir LIMIT $count") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/157885-solved-gettype-is-null/#findComment-833490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.