Help with calling data
Posted: Thu Apr 09, 2009 11:38 am
Hi - i am new to php, so excuse me if I'm being stupid.... but could you help with the following....
OK, so i want to grab data from a database, based on several criteria, say haircolor, eyecolor, gender, height
I am passing an object array to php "$data" as follows....
The $data array could have all criteria, but most likely one or two, let' say i am passing the following only
haircolor = brown
gender = female
so... to my problem... i want to check through the $data and then SELECT * FROM myTable WHERE haircolor = brown AND gender = female
but my $data array may have many more fields etc
so can i do something like...
so the SELECT FROM works with any amount of data??
This is what i usually do...
Your help would be much appreciated
Thanks
OK, so i want to grab data from a database, based on several criteria, say haircolor, eyecolor, gender, height
I am passing an object array to php "$data" as follows....
Code: Select all
public function myFunction($data){
//
}haircolor = brown
gender = female
so... to my problem... i want to check through the $data and then SELECT * FROM myTable WHERE haircolor = brown AND gender = female
but my $data array may have many more fields etc
so can i do something like...
Code: Select all
foreach($data as $field => $value) {
//
}This is what i usually do...
Code: Select all
public function getSomething($live,$name)
{
$result = mysql_query(sprintf("SELECT * FROM myTable WHERE live = '%s' AND name = '%s';", $live, $name));
$t = array();
while($row = mysql_fetch_assoc($result))
{
array_push($t, $row);
}
return $t;
}Thanks