0

I have a database table ("buildings") in MySQL consisting of 3 columns:

  • Name
  • Place
  • Number

I have created a dropdown list in my view page which contains the names of the buildings and also a textarea.

Now, depending on which name the user selects, the textarea should be populated with the respective place and number of the name of the building. I’m able to get the result but I want the output to be more readable. Right now, the format of the output is as:

Array
(
    [0] => Array
        (
            [Number] => 14
            [Place] => Cambodia
        )
)

Is there anyway I could get the output to be as simple as:

Number : 14
Place: Cambodia

Her's the model code:

<?php
class Application_Model_Building extends Zend_Db_Table_Abstract
{
    public function getname($name)
    {
        $db = $this->getDefaultAdapter();
        $auth = Zend_Auth::getInstance();
        $select = "SELECT * FROM buildings where name = $name";
        $stmt = $db->query($select);
        $result = $stmt->fetchAll();
        print_r ($result);
    }
}
?>
6
  • This is a matter of writing PHP code to access the array elements and outputting them in the manner you require. Are you familiar with the code required to access array elements, and with 'echo' or 'print' statements? Commented Jul 11, 2013 at 16:29
  • Here's my model code: Commented Jul 11, 2013 at 16:32
  • I could include the controller and ajax part as well if you want me to Commented Jul 11, 2013 at 16:35
  • The code that you posted reveals that your data is contained in an array named $result. At the risk of being repetitive, are you familiar with the ways of accessing array elements as defined in the PHP documentation? Commented Jul 11, 2013 at 16:35
  • Not really. I'm new to this. Commented Jul 11, 2013 at 16:37

1 Answer 1

1

instead of echoing the array dump, try:

foreach ($result as $vals) {
echo "Place: ".$vals["Place"]."<br>Number: ".$vals["Number"];
 }  

as other posters have commented, you should read about php arrays so you know why this makes sense

Sign up to request clarification or add additional context in comments.

Comments

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.