0

I am creating a class for an application "backbone" and I need this function to query the db, and return a multidimensional to look like this:

$myArray = ("name"=>"John", "dob"=>"January 5, 1955");

Of course the data for the array is from a database query. but, "name" and "dob" would be the database column name and "John" and "January 5, 1955" would be the value of the column

Here is my code:

public function getFrame($id) {
    $getFrameQuery = "SELECT * FROM " . DB_FRAMETABLE . "WHERE `fhid`=" . $this->quote_smart($id);
    $getFrameRecord = $db->query_first($getFrameQuery);          
}

Any help is greatly appreciated!

Josh

0

2 Answers 2

2

What database wrapper are you using? They usually provide a way to retrieve a row into an associative array.

mysql_fetch_assoc(), for example

From your comment to the other answer, the wrapper you are using provides a ->fetch_array() method that returns the data structure you are looking for.

Looks like you would need to change your code to use something like

$result = $db->query($getFrameQuery);
$data = $db->fetch_array($result);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks. What type of array did I use as an example for future reference?
@josh brown: An associative array. php.net/manual/en/language.types.array.php
you used an associative or hash array, key => value A multidimensional array could have been (key => "value1", "value2")
0

This isn't a multidimensional array. Just a regular associative array.

4 Comments

So the DB query returns a associative array?
I am using this mysql class wrapper: ricocheting.com/scripts/php_mysql_wrapper.php
Seems as if query_first() does return an associative array, the column names as keys. $getFrameRecord['name'] would get you "John"
$query = "select name from whatever"; $results = mysql_query($query) or die("Query failed: ".mysql_error()); while($row = mysql_fetch_assoc($results)){ echo $row['name']; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.