Re: Arrays
| From: | Torsten Roehr | Date: | Wed, 28 Apr 2004 10:25:40 +0000 |
| Subject: | Re: Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184853@lists.php.net to get a copy of this message | ||
>"Fannehh Adevarap" <fannehh@adevarap.ro> wrote in message
news:001701c42d08$c3e79960$5600a8c0@fannehh...
>I have a problem with arrays.
>
>I have this script:
>
>$query = "SELECT model_name, brand_name FROM products WHERE
product_id='$product_id'";
>
>$result = mysql_query($query) or die("error in query -
$query -".mysql_error());
>
>while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
>
>foreach ($line as $element) {
>$jelement[] = $element;
>
>}
>}
Do this:
$modelNames = array();
$brandNames = array()
while(list($model_name, $brand_name) = mysql_fetch_row($result)) {
$modelNames[] = $model_name;
$brandNames[] = $brand_name;
}
Regards, Torsten
>
>i want each element to be stored in a different array.
>
>For ex: If i print now the array $jelement i have:
>
> model_name1-brand_name1
> model_name2-brand_name2
> .........
>
>I want 2 arrays: array1 will contain [model_name1,model_name2, ....] and
array2 [brand_name1,brand_name2......]
>
>
>How can i do that?
>
>Thanks