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.
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.
Depending on your other constraints, you might solve problem #3 by putting the image in an <iframe> and letting html do the work.
#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.
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