Re: URGET HELP : Logic Help - for first record do_this foreach record after do_that

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

 



$x = 1;
while($row = mysql_fetch_array($result)) {
    if ($x) {
        do_something();
        $x = 0;
        continue;
    } else {
        do_something_else();
    }
}

This sets $x = 1 before the loop.  The first time it goes through the loop
it does something for the first record and sets $x = 0;  Every time you
loop through after that $x will equal 0 and that do_something_else()
condition will be used for every subsequent loop.

Peter

On Fri, 25 Oct 2002, Aaron Wolski wrote:

>
> Hey guys,
>
> Not really off topic as this involves some Db work as I have to query
> the DB.
>
> Got a logic problem that was jumped dumped on me from UPS (dummys!).
>
> Basically I need to pull some records out of a database and for the
> first record do_this logic and for each record after in the array
> do_something_else logic.
>
> How would I approach this?
>
> something like:
>
> for ($first_record) {
>
> do_something;
>
> } else {
>
> do_something_else;
>
> }
>
> Any clues?
>
> Thanks!
>
> Aaron
> > -----Original Message-----
> > From: Graeme McLaren [mailto:mickel@ntlworld.com]
> > Sent: Friday, October 25, 2002 2:40 PM
> > To: php-db@lists.php.net
> > Subject:  Inserting checkbox data
> >
> >
> > Hi all, I'm having a problem inserting a value from a
> > checkbox into a MySQL DB.  I can print out what the variable
> > holds, the problem is it just won't go into the DB.  Weird
> > thing is when I login to SSH there isn't a NULL value for it
> > instead that field is just blank.
> >
> > Anyone got any ideas what the problem is?
> >
> >
> > The HTML that is used for the checkbox is:
> >
> > Gift Wrapping: <input type=checkbox Name=GiftWrapping[] Value=\"Y\">
> >
> >
> > So it should theoretically insert "Y" into the DB
> >
> > Here is the code that appears to be causing the problem:
> >
> > $number=count($GiftWrapping);
> >  for($a=0;$a<=$number;$a++)
> >  {
> >      echo $GiftWrapping[$a];
> >      $GW = $GiftWrapping[$a];
> >      echo $GW;
> >  }
> >
> >     if ($Submit == "Submit") {
> >       $sql = "INSERT INTO SiteMember SET
> >                 FirstName = '$FirstName',
> >                 LastName = '$LastName'
> >                 Username = '$Username',
> >                 Password = '$Password',
> >                 GiftWrapping = '$GW'";
> >  }
> >
> >
> > Thank you in advance for any help.
> >
> > Graeme :)
> >
> >
> > Public Sub House()
> >
> > On Error Resume drink
> >
> >          If Pint.empty = True Then
> >                  Pint.refill
> >    Else
> >                  Pint.drink
> >          End if
> >
> > stomach.add Pint
> >
> > MsgBox " I've had .... " & stomach.count & " Pints"
> > MsgBox "VERY DRUNK"
> >
> > End Sub
> >
> >
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

---------------------------------------------------------------------------
Peter Beckman            Systems Engineer, Fairfax Cable Access Corporation
beckman@purplecow.com                             http://www.purplecow.com/
---------------------------------------------------------------------------


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux