Re: One more newbie question. About foreach..
| From: | Tim Streater | Date: | Sun, 23 Jun 2013 15:51:00 +0000 |
| Subject: | Re: One more newbie question. About foreach.. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-321464@lists.php.net to get a copy of this message | ||
On 23 Jun 2013 at 16:11, Karl-Arne Gjersøyen <karlarneg@gmail.com> 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