SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    The site I'm working on at the moment which uses a lot of numbers to access data from a MySQL table.

    Due to the nature of the site, it will require large numbers very quickly, however these revert to "scientific notation" when stored as variables.

    I used the settype function to set the variables to integers, but the largest number I can have with this is 2147483647 which is still not large enough.

    I tried using double or string with the settype function, but this just caused the scientific notation problem again.

    any suggestions?
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you need a signed or unsigned int? If unsigned, then how is this for a range of values: 0 to 18446744073709551615 ? Thats an unsigned bigint in MySQL. http://www.mysql.com/doc/C/o/Column_types.html

    Oh, maybe I've misunderstood. Are you talking about representing the numbers in PHP?

  3. #3
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I may have confused you, and myself in the process.

    take a look at this code

    Code:
    <?
    settype($id_chapter, integer);
    
    $id_chapter_loop = $id_chapter;
    
    settype($id_chapter_loop, integer);
    
    while ($id_chapter_loop != 0)
    	{
    	print ("$id_chapter_loop<br>");
    
    	// getting previous chapter number.
    	$ooe=$id_chapter_loop%2?0:1;
    	if ($ooe == 1)
    		{
    		$id_chapter_loop = $id_chapter_loop/2;
    		}
    	else
    		{
    		$id_chapter_loop = ($id_chapter_loop-1)/2;
    		}
    	}
    ?>
    this code cak be found at http://writeoutthere.com/viewall.php

    now if I pass the variable of 999999999999999 into the script via the URL (eg http://writeoutthere.com/viewall.php...99999999999999) PHP automaticly converts it to 2147483647 (as you can see at the top of the page).

    what I need it to do is keep the number of 999999999999999 and not change to anything else.

    Does that make better sence?
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, no idea!?! I've never counted that far Perhaps you could try passing the value in hexidecimal format?!?

  5. #5
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Store the number as a string and write your own mathematical operators. It's not as hard as it sounds... it was a requirment to do this for the AP CS class way back in high school.

    Anyway, a more realalistic solution is... I know there are modules to get around this for Perl, and I bet there are in PHP. (for Perl'ers: "use Math::BigInt")

    Owen

  6. #6
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Owen
    Anyway, a more realalistic solution is... I know there are modules to get around this for Perl, and I bet there are in PHP. (for Perl'ers: "use Math::BigInt")
    Owen
    And this would allow me to store much larger numbers? Does anyone have any ideas on this?

    It will be a major help for me if someone could work this out (please, please, please, please, please, please, please, please)
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  7. #7
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if you store the number as TEXT then convert it to a BigInt when you use it, then you can store any number, as big as you want (w/in obvious reason, of course), in the db.

    Owen

  8. #8
    Idea Developer
    Join Date
    Sep 2000
    Location
    Bethlehem, PA
    Posts
    521
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use bigint

  9. #9
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, this has solved my problem for how to store them in the database, but it still does not help the problem on the script, esp as the URL will be used to access the info.

    I show you another example:

    Code:
    <?
    settype($no, integer);
    print($no);
    ?>
    now if I pass a number into the script via the url:

    eg, .php?no=999999999999999999999999999999999999

    this will convert to 2147483647, how do I prevent this?

    ps, the above code can be found at http://www.writeoutthere.com/new.php

    the link example i'm talking about is http://www.writeoutthere.com/new.php...99999999999999
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  10. #10
    Idea Developer
    Join Date
    Sep 2000
    Location
    Bethlehem, PA
    Posts
    521
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stick to smaller numbers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •