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']; } ?> Quote 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? Quote 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()); Quote Link to comment https://forums.phpfreaks.com/topic/157885-solved-gettype-is-null/#findComment-833490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.