Need Help With 2 Questions

Discussion in 'PHP' started by Imozeb, Apr 24, 2010.

  1. #1
    1. How do I preg_replace white space into under_scores?

    2. How do I use ORDER BY in MySQL/PHP on a number like (7/25)
    I tried this but it isn't working where `number` is the field that contains a variable fraction.


    Code:
    ORDER BY CAST(`number` AS DECIMAL) DESC
    Code (markup):
    3. How do I use PHP to check the canvas size of an image and reduce it to 50px,50px?

    Thanks.
     
    Last edited: Apr 24, 2010
    Imozeb, Apr 24, 2010 IP
  2. Brad33

    Brad33 Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1. You can use str_replace()

    $replaced = str_replace(" ","_",$string);
    PHP:
    2. Perhaps you could pull the data then sort it with php? It would probably be easier since you are using fractions like that, either that or convert the fractions to float then input them into your database.

    3. If you need to resize an image, here's a class you can look at... [Link] Seems simple enough to use.
     
    Brad33, Apr 24, 2010 IP
  3. Chipzzz

    Chipzzz Member

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Depending on your other constraints, you might solve problem #3 by putting the image in an <iframe> and letting html do the work.
     
    Chipzzz, Apr 25, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    #1 is solved. I'm looking into #3. But #2 is not solved.

    I cannot use PHP to sort the rows because: one, there are a huge number of rows in the database and querying all that information will result in a performance hit. two, I am using MySQLs LIMIT command to limit the output. three, I need to store the values as a fraction. Shouldn't MySQLs CAST to DECIMAL statement work? If not how would I do it using MySQL?

    Thanks.
     
    Imozeb, Apr 25, 2010 IP
  5. Chipzzz

    Chipzzz Member

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    For #2, I think the only way you can do it with any reasonable efficiency is by adding a column to your table and putting the calculated decimal equivalent of the number in it. If you do the calculation in PHP immediately before the row is inserted, the overhead should be acceptable. After that, the sorting problem becomes trivial.

    Good luck with your project.

    Chipzzz
     
    Chipzzz, Apr 25, 2010 IP