Hello, Okay, so I am a PHP newbie, arghhh, but I am willing to learn 🙂 ...
So I have script that I need some help with. I am not very familiar with associative arrays in PHP, so if anyone is willing to help I would appreciate it a million times over!!!
Here is my script. What I need to be able to so is query my db, which is already set up in the script below and then return the data in an associative array...
The structure is already built below, I am just not sure how to get the data from the db into an associative array. I have Googled for a tutorial,
but alas, this is where I wound up...
Here is my script. I have tried to comment as much as I can for clarity of what I am trying to do...
class Plots {
function findAll($id) {// i am passing the id... this is just used to search the id key in the db...
mysql_connect("$dbserver", "$dbusername", "$dbpassword") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error());// make the mysql connnection...
$result = mysql_query("select * from plots where plat_map_id is '$id'");// get the results...
// arguments
// return: An array of all the plots. Each element (plot) in the
// array is an associative array. The keys of the associative
// array are the column names from the database and the values of the
// associative array are the values of those columns from the database
return array(// i have a lot of records in the db, i am just showing two for this example...
array('id' => 1,
'plat_map_id' => 1,
'address' => '1234 Julie Lane',
'city' => 'Some City in America',
'state' => 'ID',
'lot' => '1545A',
'block' => '4',
'model' => 'ABC',
'homeowner' => 'Virgil',
'property_status_id' => 1,
'close_date' => '2007-12-31',
'contracted_date' => '2007-06-01',
'square_feet' => '1300',
'x' => 134,
'y' => 399),
array('id' => 2,
'plat_map_id' => 1,
'address' => '1234 Julie Lane',
'city' => 'Some City In America',
'state' => 'ID',
'lot' => '1545A',
'block' => '4',
'model' => 'ABCDEF',
'homeowner' => 'Virgil',
'property_status_id' => 3,
'close_date' => '2007-12-31',
'contracted_date' => '2007-06-01',
'square_feet' => '1300',
'x' => 296,
'y' => 392),
}
}