11-02-2016, 03:14 AM
I've begun working on this and have reached a frustration point. I'm brand new to PDO and the like and I can't seem to get a simple query to work. For identifying the "id" of the page we're on, I've added this simple function to the helpers.php file.
function currentPage_id() {
$current_page_url = currentPage();
$db = DB::getInstance();
$query = $db->query("SELECT id FROM pages WHERE page = users/" . $current_page_url);
$results = $query->first();
$current_page_id = $results->id;
//echo '$current_page_id: ' . $current_page_id;
return $current_page_id;
}
A couple things then...
1.) Why do we need the "$query->first();" part? It seems like "$query->results();" should work, but it doesn't.
2.) The current code constantly returns "1". For example, on the admin.php page, it should return 4.
Any ideas on why this is failing?
function currentPage_id() {
$current_page_url = currentPage();
$db = DB::getInstance();
$query = $db->query("SELECT id FROM pages WHERE page = users/" . $current_page_url);
$results = $query->first();
$current_page_id = $results->id;
//echo '$current_page_id: ' . $current_page_id;
return $current_page_id;
}
A couple things then...
1.) Why do we need the "$query->first();" part? It seems like "$query->results();" should work, but it doesn't.
2.) The current code constantly returns "1". For example, on the admin.php page, it should return 4.
Any ideas on why this is failing?