Re: One more newbie question. About foreach..

[email protected] (Tim Streater)
Newsgroups php.general
Message-ID <[email protected]>
On 23 Jun 2013 at 16:11, Karl-Arne Gjersøyen <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.