Jump to content

[SOLVED] gettype is null??


The Little Guy

Recommended Posts

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

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.