Re: One more newbie question. About foreach..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23 Jun 2013 at 16:11, Karl-Arne Gjersøyen <karlarneg@xxxxxxxxx> wrote: 

> // Foreach get all given serialnumbers as I want it
>    foreach($serialnumber as $snr){
>
> // I got the number of serialnumbers given in the array
>   $count = count($serialnumber);

Why not do this *before* the foreach loop?

> // I thought that a for loop would do the trick together with foreach
> // And repeat the $sql = SELECT below but that did not happen.
>    for($i = 0; $i <= $count; $i++){
>
>
> // Connect and get only those records with given serialnumber
> $sql = "SELECT * FROM explosive WHERE serialnumber = '$snr'";
>    } // End of for loop
>    } // End of foreach loop

All this for loop does is overwrite $sql each time.

> $result = mysql_query($sql, $connect) or die(mysql_error());
> $count = mysql_num_rows($result);

You need to have your mysql_query *inside* the for loop. Then, what are you doing with the results of the mysql_query? Nothing?

Also, why do you need the for loop anyway? What is it supposed to do?

--
Cheers  --  Tim

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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux