Re: selecting one item at a time from mysql
| From: | scottrus at ipass dot net | Date: | Sun, 17 Sep 2000 17:49:56 +0000 |
| Subject: | Re: selecting one item at a time from mysql | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17137@lists.php.net to get a copy of this message | ||
Richard, well, first thing to do is to add another column to your MySQL DB.
Use the MySQL alter table statment to add in the ipstatus column. An
unsigned tinyint should do the trick. Also, set the default value to be
0, all though I think MySQL does this already for int type columns. Finally
make it 'not null' since you never want this column to have a null value.
Since you had a concern that multiple customers signing up within the 15min span
you would do something like this: (sudo code only 'cuase it's late here for me :)
use mysql_connect to attache to the db.
start a loop for the number of queries we need
use mysql_db_query to select the next record:
select <colname> from <table> where ipstatus = 0 order by <colname> limit 1;
call setup_ip_function() which you've defined to setup the customer env with
the new ip.
user mysql_db_query to update the ip changing the status to 1;
update <table> set ipstatus = 0 where ipaddr = <ipaddr from prev query>;
end loop
call mysql_close to close the db connection.
end php script
Based on your original question I think that's what you want, or something
along those lines. Using this kind of setup you can even go to the next level
and make a customer table that contains such items as: name, address, type, service
info and a customer_id. Then you can add a customer_id column to your ipaddr table which
holds the unique customer_id number. This way you can see which ips are assigned to which
customers at any given time.
Maybe this is more than what you wanted to to but it's a direction you might want to
consider.
-- Scott
On Sun, Sep 17, 2000 at 03:55:31PM -0700, Richard Kurth wrote:
> Hello scottrus,
>
> Sunday, September 17, 2000, 6:40:26 AM, you wrote:
>
> sin> Maybe if you add another col to your ipaddr table you can do what
> sin> you want. Call the column 'ipstate' and give it a value of 0-2.
>
> sin> 0 = not in use
> sin> 1 = in use
> sin> 2 = active config
>
> sin> When I user first requests and IP select all the ip's where state
> sin> is 0. Take the first one off the top and set it to state = 2 meaning
> sin> a user is about to check it out.
>
>
>
> I like your first idea with second col . I don't have to worry about a
> user accessing this script it runs at the command line at root run by
> cron every 15 min. I guess my next question is how do I implement this
> process. What would the mysql process look like.
>
>
>
>
> --
> Best regards,
> Richard mailto:rkurth@pacifier.com
>
--
Scott