Re: selecting one item at a time from mysql
| From: | scottrus at ipass dot net | Date: | Sun, 17 Sep 2000 13:40:26 +0000 |
| Subject: | Re: selecting one item at a time from mysql | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17101@lists.php.net to get a copy of this message | ||
Maybe if you add another col to your ipaddr table you can do what
you want. Call the column 'ipstate' and give it a value of 0-2.
0 = not in use
1 = in use
2 = active config
When I user first requests and IP select all the ip's where state
is 0. Take the first one off the top and set it to state = 2 meaning
a user is about to check it out.
Once the checkout process has completed set the ipstate to 1 for
checked out. This represents a 'deleted' ip address.
Once the ip can be checked back into the db just switch the ipstate
to 0 again.
If this simple scheme doesnt' work for you the next step is table
locks, but be careful. You never want to lock a table while you wait
for a user input because if the user starts the process but then goes
to lunch your table is locked from further updates.
-- Scott
On Sun, Sep 17, 2000 at 02:36:22PM -0700, Richard Kurth wrote:
> Hello SoNix,
>
> Sunday, September 17, 2000, 3:05:39 PM, you wrote:
>
> SH> Hummm
>
> SH> Why not use
> >> $query1 = "SELECT * FROM ipaddress WHERE
> >> ip_address='$REMOTE_ADDR'"
> SH> No ???
>
> The address are all new and just stored in the database there is
> nothing to reference them to. I just want to get one at a time out of
> the database for use in the script. Maybe I am making a bigger deal out of
> this than there is.
>
>
> >> I have a table that just has unused ip address's in it. What I what to
> >> do is pull one address out of the database at a time so that I can use
> >> it in the script that adds new customers to a hosting sit. After I use
> >> that ip address it will be deleted from the table.
> >> I am using something like this
> >>
> >> $query1 = "SELECT * FROM ipaddress";
> >> $result1 = mysql_query ($query1) or
> >> die("Error in query");
> >> while($myrow1 = mysql_fetch_array($result1))
> >> {
> >> $ipaddress = $myrow1["ip"];
> >>
> >> It works just fine if I don't have more than one person signing up at a
> >> time. I could use the LIMIT switch to just get the first record but
> >> then if I have a second person that is in the database to be signed up
> >> I would have to run the query again. (The program is run by cron and
> >> looks in a database to see if there are any new subscribers if there are
> >> it grabs them and runs all of them thru the script each one needs a
> >> different ip address) All I what to do is grab another IP address each
> >> time the program comes to a new subscriber without having to run the
> >> script over again. Do I make any sense.
>
>
>
>
>
>
> --
> Best regards,
> Richard mailto:rkurth@pacifier.com
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net