Re: Arrays
| From: | Torsten Roehr | Date: | Wed, 28 Apr 2004 10:29:11 +0000 |
| Subject: | Re: Arrays | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184854@lists.php.net to get a copy of this message | ||
"Torsten Roehr" <roehr@zilleon.com> wrote in message
news:20040428102324.8796.qmail@pb1.pair.com...
> >"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()
Sorry, forgot an ; here:
$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