Reply to Re: Query returning array

Your name:

Reply:


Posted by Hendri Kurniawan on 04/20/07 04:16

Karl Groves wrote:
> I'm missing something very obvious, but it is getting late and I've
> stared at it too long.
>
> TIA for responses
>
>
> I am writing a basic function (listed at the bottom of this post) that
> returns data from a query into an array.
>
> The intent is that the following code:
> $foo = dbSelectData("SELECT foo, bar FROM table", $link);
> would return an array with the keys: 'foo' and 'bar'.
>
> But what I get is instead a multidimensional array.
> Doing a var_dump on $foo turns out to be
> array(2) {
> ["foo"]=>
> string(5) "Stuff"
> ["bar"]=>
> string(10) "More Stuff"
> }
>
>
> I'm wondering where I went wrong in writing the function below.
>
>
> function dbSelectData($query, $connection, $rtype=MYSQL_ASSOC){
>
> $result = mysql_query($query, $connection);
> if(!$result){
> dbThrowError("Error in function dbSelectData. Query Was <em>
> $query</em>.");
> return FALSE;
> }
> else{
> $numrows = mysql_num_rows($result);
>
> if($numrows == 0){
> return FALSE;
> }
> else{
> while($rows = mysql_fetch_array($result, $rtype)){
> $output[] = $rows;
> }
> mysql_free_result($result);
> return $output;
> }
> }
> }
>
>
> Thanks in advance.
>

That's weird, your code seems to be working on my box.
The only thing that i can think of right now that would return that
result is when you return $rows instead of $output.... or when you
assign your $rows to $output, you forgot the bracket (ie. $output[] =
$rows) .... but that is not the case with you posted code

Hendri Kurniawan

Hendri Kurniawan

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация