Query table / results to an array

Query table / results to an array

am 29.02.2008 06:22:51 von Ron Piggott

I need help populating an array based on the output of a mysql query.


$reference_number is a value assigned by auto_increment
$description is what I want the value of the array to be --- a few words
in length

$reference_number = mysql_result($search_result,$i,"reference_number");
$description = mysql_result($search_result,$i,"description");

Ron

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Query table / results to an array

am 29.02.2008 06:39:49 von dmagick

Ron Piggott wrote:
> I need help populating an array based on the output of a mysql query.
>
>
> $reference_number is a value assigned by auto_increment
> $description is what I want the value of the array to be --- a few words
> in length
>
> $reference_number = mysql_result($search_result,$i,"reference_number");
> $description = mysql_result($search_result,$i,"description");


$references = array();

$result = "select id, description from table";
while ($row = mysql_fetch_assoc($result)) {
$references[$row['id']] = htmlentities($row['description'],
ENT_QUOTES, 'ISO-8859-1');
}

print_r($references);


--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Query table / results to an array

am 29.02.2008 06:56:55 von dmagick

Ron Piggott wrote:
> This line of code
>
> while ($row = mysql_fetch_assoc($result)) {
>
> Gave me this error message:
>
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
> result resource
>
> I ran
>
> select reference, description from table
>
> in mySQL and it worked --- Any idea what caused the error?

Oops..

$result = mysql_query("select id, description from table");


> On Fri, 2008-02-29 at 16:39 +1100, Chris wrote:
>> Ron Piggott wrote:
>>> I need help populating an array based on the output of a mysql query.
>>>
>>>
>>> $reference_number is a value assigned by auto_increment
>>> $description is what I want the value of the array to be --- a few words
>>> in length
>>>
>>> $reference_number = mysql_result($search_result,$i,"reference_number");
>>> $description = mysql_result($search_result,$i,"description");
>>
>> $references = array();
>>
>> $result = "select id, description from table";
>> while ($row = mysql_fetch_assoc($result)) {
>> $references[$row['id']] = htmlentities($row['description'],
>> ENT_QUOTES, 'ISO-8859-1');
>> }
>>
>> print_r($references);
>>
>>
>
>


--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Query table / results to an array

am 29.02.2008 20:14:18 von parasane

On Fri, Feb 29, 2008 at 12:22 AM, Ron Piggott
wrote:
> $reference_number = mysql_result($search_result,$i,"reference_number");
> $description = mysql_result($search_result,$i,"description");

$sql = "SELECT reference_number FROM table WHERE this='whatever' OR
that NOT LIKE '%whatever%' LIMIT 0,1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>

Just mind the line-wrapping in this message. ;-P

--


Daniel P. Brown
Senior Unix Geek


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php