This might really confuse you, but I'll try my best.
I'm attempting to very slowly redo my blog into OOP. I'm creating a class that allows you to give it parameters. Those are then inserted into the MySQL query. EG
Code:
class content {
//START OF CONTENT CLASS
function connect_db($user, $db) {
$conn = mysql_connect("localhost", $user, "") or die(mysql_error());
mysql_select_db($db, $conn) or die(mysql_error());
}
function get($table, $selector = "*", $where = "", $limit = "", $orderby = "", $order = "") {...
Basically I want the variables $where, $limit, $orderby and $order to not be needed. So, as you can see, I have set their defaults to nothing.
I need to check if the user has included them, and if they have, add them to the MySQL statement. My plan was to create functions like:
Code:
function where() {
if ($where !== '') {
echo 'WHERE ' . $where .'';
}
}
So if where actually has a value, it ends up as (in this example)
Code:
echo WHERE id = '1';
But if I'm right a function cannot be included in the query? Ideally it would be:
Code:
$query = mysql_query("SELECT '$selector' FROM '$table' where();");
That incorporates the function where. I've tried it and it gave an error. Is it possible? Is there another way round it?
Jack
---
Also,
Code:
function get($table, $selector = "*", $where = "", $limit = "", $orderby = "", $order = "") {
if (mysql_query("SELECT '$selector' FROM '$table'")) {
echo 'Query Fine';
}
And then:
Code:
$all->get('content', 'id');
Is not working. I know nothing will display, but surely it should say 'Query Fine'. Any ideas anyone?