I'm trying to learn OOP and i'm trying to create a class which will select me info from a table and a line that i choose. (trying my best to explain it good, not sure if i'm doing very well tho)
This is my code in the class:
class SelectQuery {
public function db_select($query_table, $query_extra) {
//$result = mysqli_query($conn, "SELECT * FROM `ideas` WHERE `Accepted` = 1 ORDER BY RAND() LIMIT 1");
//$query = 'SELECT * FROM '.$query_table.' '.$query_extra.'';
//$results = $this->con->query($query);
$this->con = mysqli_connect('localhost', 'root', '', 'forum');
$results = $this->con->prepare('SELECT * FROM '.$query_table.' '.$query_extra.'');
$results->execute();
return $results;
}
}
And this is the code in the actual page:
include_once 'Classes/SelectQuery.php';
$SelectQuery = new SelectQuery();
$query_table = 'category';
$query_extra = '';
$SelectQuery->db_select($query_table, $query_extra);
$date = $db_select->$result;
$date = mysqli_fetch_assoc($result);
echo $date;
while($categories = $result->fetch_assoc())
{
echo '<p>';
echo $categories['ID'].' ';
echo $categories['Name'].'</p>';
while($forums = $result_forum->fetch_assoc())
{
echo $categories['Name'].'</p>';
}
}
The problem isnt in the class(i think), it's in the actual page when i'm trying to get the info that i want, there is no error until here:
$SelectQuery->db_select($query_table, $query_extra);
but after that line when i'm trying to really get the info there is a lots of errors and i'm probably doing it wrong... i would like to know how can i fix it, thanks :)