Jump to content

MDB2 Query Result Format


kakster

Recommended Posts

I've hit a wall trying to get MDB2 to give me the results of my database query in the format I want. I'm probably misunderstanding something about MDB2, so please enlighten me.

 

 

The SQL below, when executed from a MySQL command line, returns what I want:

 

First Building Name

Second Building Name

Third Building Name

Forth Building Name

 

... so I know it's not the SQL causing the problem.

 

 

Now the MDB2 code:

 

$sql = 'SELECT DISTINCT Property
FROM Table1
INNER JOIN Table2
ON Table1.Id=Table2.Table1Id
ORDER BY Property ASC';

$result = $mdb2->query($sql);
errorCheck($result);  // Check that result is not an error.
$data = $result->fetchAll(MDB2_FETCHMODE_ORDERED);  // Gives an array of all rows at once.
$result->free();  // Free all memory associated with queries.
print_r($data);

 

 

MDB2 returns the data in this format:

 

Array (
    [0] => Array (
            [0] => First Building Name
    )

    [1] => Array (
            [0] => Second Building Name
    )

    [2] => Array (
            [0] => Third Building Name
    )

    [3] => Array (
            [0] => Forth Building Name
    )
)

 

 

I want the data in this format instead:

 

Array (
    [0] => First Building Name

    [1] => Second Building Name

    [2] => Third Building Name

    [3] => Forth Building Name
)

 

Thank you :-)

 

Nick

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.