Jump to content

[SOLVED] php mysql help


calmchess

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/
Share on other sites

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.

 

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419461
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419465
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/82514-solved-php-mysql-help/#findComment-419511
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.