Hi there,
Please can someone help me!
I have recently been learning oop PHP. I have created a class for my database, which basically makes my life easier when doing queries.
I have created a "where" method which basically when used will append to the select statement.
For example:
//class I have created
$query = new MySqlDb;
//this is the where statement
$query->DbWhere("LULevel='10' && LUId='200'");
//db select statement
$res = $query->DbSelect("*", "login","ORDER BY LUFName ASC");
Now the above code works absolutely fine but the value for the where method is: "LULevel='10' && LUId='200'".
I want to neaten it up so I only need to enter the property and the value like this: "$query->DbWhere("LULevel","10","LUId", "200");" so I can use mysql_real_escape_string just on the value etc.
This is fine when it comes to maybe inputting one set of property and value like: ("LUId","200") but if you were to add more like:("LULevel","10","LUId", "200","LUName","bob") then I need the code to work out that there is more property and values which then gets appended to the select statement in a correct way.
I know that there is a way of maybe using array or array_key and combining it with for each loops etc but I can't work it out.
I have built a test function below which is on the same lines of what my method in the class does.
//test function
function where($prop, $val){
$where = array();
$where[$prop] = $val;
return $where;
}
print_r(where("LUName","bob","LUId","200"));
If you test the above function code, it will only print the first set:
//output
Array ( [LUName] => bob )
So just to reiterate I want to be able to get all the property and values and not just the first one.
Hope someone can help!
Thanks
Jat