calmchess Posted December 20, 2007 Share Posted December 20, 2007 I need to create 2 records in a mySQL database using php. 1 of the records holds a "counter integer" the other record holds a refrence integer. The complex part is when a user connects to the php page i need it to get the "counter integer" from the database and increment the number by 1 and if the counter integer is between 0-3 then the refrence number is stored as 1 but when the counter integer gets between 4-8 then the refrence number is a 2......i need to do this for an infinate number of counter integers.....could somebody plz help me get started with the logic i'm an intemediate programmer but this logic seems a little complex and i could really use a jump start on how to go about programming this in php. Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/ Share on other sites More sharing options...
revraz Posted December 20, 2007 Share Posted December 20, 2007 Assuming you know how to get the data from the database already and how to write it back. <?php //variables are from the db $counter = 1; $counter += 1; if ($counter >= 0 AND $counter <= 3) { $reference = 1; } elseif { if ($counter >= 4 AND $counter <= 8 ) { $reference = 2; } ?> You can also use SWITCH and CASE as well if you have more to compare, but this is the general idea. ?> Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419461 Share on other sites More sharing options...
calmchess Posted December 20, 2007 Author Share Posted December 20, 2007 that gives me stuff to work with but i need to build an effiecent application for an indefinate number of counter and refrence numbers....there will hopefully be over 1000 users connected at any 1 time and each user needs a refrence number assigned to them the script i have described here will be part of a much larger login script.....if you don't have any thing else to contribute to this thread at this time then I think you for the time you have already invested. Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419465 Share on other sites More sharing options...
revraz Posted December 20, 2007 Share Posted December 20, 2007 How will the pattern work? You'll have to come up with a forumula to create the variables to use based on what number pattern you want. 0-3 4-8 ?-? Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419468 Share on other sites More sharing options...
calmchess Posted December 20, 2007 Author Share Posted December 20, 2007 well i want a new refrence integer everytime 4 users sign up for an account. Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419507 Share on other sites More sharing options...
GuitarGod Posted December 20, 2007 Share Posted December 20, 2007 Probably divide the counter by 4 to get your reference integer. <?php $count = 24 $integer = $count / 4; // Integer above will equal 6 /* Lets check if it works with your pattern 0 - 3 = 1 4 - 8 = 2 9 - 13 = 3 14 - 18 = 4 19 - 23 = 5 24 - 18 = 6 */ ?> Yup, it works. Have fun Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419511 Share on other sites More sharing options...
calmchess Posted December 20, 2007 Author Share Posted December 20, 2007 simple math to the rescue ...... Quote Link to comment https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.