Database Forum
Web Database Register Members List Calendar FAQ

 
Go Back   Database Forum > PHPMagic Discussions > Customization
User Name
Password

Reply
 
Thread Tools Search this Thread Display Modes
Default Round function
02-09-2011, 01:11 PM #1  

oklaslim
Junior Member

 
Status: Offline
Posts: 7
Join Date: Feb 2011

I created the following code with PHPMagic Plus and it is working fine and produces the correct results. What I need to do is use the Round() funtion on the calculated colums, everything I have tried produces a syntax error.

I want to get that working first, then I have another function I need to add. If someone could help me with the correct syntax I would appreciate it. I am quite pleased with PHP Magic.

Thanks

$x->Query = "select Round1.Rnd_ID as 'Rnd_ID', Round1.Rnd_Num as 'Rnd_Num', Round1.Date_Time as 'Date_Time', Player_Master4.NickName as 'Player1_ID', Round1.Player1_Raw as 'Player1_Raw', (250-(Player_Master4.Total_Raw/Player_Master4.Games)) as 'Player1_Hand', (Round1.Player1_Raw + (250-(Player_Master4.Total_Raw/Player_Master4.Games))) as 'Player1_Total', Player_Master8.NickName as 'Player2_ID', Round1.Player2_Raw as 'Player2_Raw', (250-(Player_Master8.Total_Raw/Player_Master8.Games)) as 'Player2_Hand', (Round1.Player2_Raw + (250-(Player_Master8.Total_Raw/Player_Master8.Games))) as 'Player2_Total' from Round1, Player_Master as Player_Master4, Player_Master as Player_Master8, membership_userrecords where Round1.Player1_ID=Player_Master4.Player_ID and Round1.Player2_ID=Player_Master8.Player_ID and Round1.Rnd_ID=membership_userrecords.pkValue and membership_userrecords.tableName='Round1' and membership_userrecords.memberID='".getLoggedMember ID()."'";
Reply With Quote

Default
02-09-2011, 05:06 PM #2  

Kayla
Senior Member

 
Status: Offline
Posts: 302
Join Date: Mar 2005
Location: USA

Hi -

What is the datatype and name of the field that you want to round.
Also what type of rounding? up,down,decimal place.

Code:
Maybe this helps:

<?php echo round(3.14159265); // Value would be 3
echo round(3.9); // Value would be 4 
echo round(3.14159265, 3); // Value would be 3.142 
echo round(314159, -100); // Value would be 314100 
?>


Rounding up:
<?php echo ceil(3.14159265); // Value would be 4 
echo ceil(3.00000001); // Value would be 4 
echo ceil(-3.14159265); // Value would be -3 
?>

Rounding Down:
<?php echo floor(3.14159265); // Value would be 3 
echo ceil(3.99999999); // Value would be 3 
echo ceil(-3.14159265); // Value would be -4 
?>

Formatting numbers:
<?php number_format (1234.567); //Returns the number 1,235  
number_format (1234.567, 2); //Returns the 
number 1,234.57  number_format (1234.567, 2, ',', ' '); //Returns the number 1 234,57  
number_format (1234.567, 1, 'a', 'b'); //Returns the number 1b234a6
I did not see your rounding operation in the code you posted.
Reply With Quote

Smile I got it
02-10-2011, 08:12 AM #3  

oklaslim
Junior Member

 
Status: Offline
Posts: 7
Join Date: Feb 2011

Thanks Kayla but I got it figured out last night, I don't understand what happened because I am sure I had tried the same thing before, but now it is working as follows:

$x->Query = "select Round1.Rnd_ID as 'Rnd_ID', Round1.Rnd_Num as 'Rnd_Num', Round1.Date_Time as 'Date_Time', Player_Master4.NickName as 'Player1_ID', Round1.Player1_Raw as 'Player1_Raw', Round(250-(Player_Master4.Total_Raw/Player_Master4.Games)) as 'Player1_Hand', Round(Round1.Player1_Raw + (250-(Player_Master4.Total_Raw/Player_Master4.Games))) as 'Player1_Total', Player_Master8.NickName as 'Player2_ID', Round1.Player2_Raw as 'Player2_Raw', Round(250-(Player_Master8.Total_Raw/Player_Master8.Games)) as 'Player2_Hand', Round(Round1.Player2_Raw + (250-(Player_Master8.Total_Raw/Player_Master8.Games))) as 'Player2_Total' from Round1, Player_Master as Player_Master4, Player_Master as Player_Master8, membership_userrecords where Round1.Player1_ID=Player_Master4.Player_ID and Round1.Player2_ID=Player_Master8.Player_ID and Round1.Rnd_ID=membership_userrecords.pkValue and membership_userrecords.tableName='Round1' and membership_userrecords.memberID='".getLoggedMember ID()."'";

Don't go away I am sure I will have more ????
Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 03:38 AM.

Powered by: vBulletin Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Database Forums

Help support our forum assistants and product development ->

go to top go to top