Jump to content

tail

Members
  • Posts

    125
  • Joined

  • Last visited

    Never

Everything posted by tail

  1. Is there a way to optimize this query so I don't have to use so many subqueries? SELECT COUNT( hits ) AS `unique` , SUM( hits ) AS `total` , ( SELECT SUM( `hits` ) FROM `stats` WHERE `date` > UNIX_TIMESTAMP( ) -86400 ) AS `today` , ( SELECT SUM( `hits` ) FROM `stats` WHERE `date` > UNIX_TIMESTAMP( ) -604800 ) AS `week` , ( SELECT SUM( `hits` ) FROM `stats` WHERE `date` > UNIX_TIMESTAMP( ) -2419200 ) AS `month` , ( SELECT COUNT( * ) FROM `stats` WHERE `online` > UNIX_TIMESTAMP( ) - '600' ) AS `online` FROM `stats` Thanks in advance!
  2. I got to this point: SELECT info.id , info.name FROM info LEFT OUTER JOIN rating ON rating.game_id = info.id GROUP BY info.id HAVING COUNT(rating.rating_value) >= 10 ORDER BY AVG(rating.rating_value) DESC However only games with > 10 votes showed in the result. How can I make it so all of the games show up, but order priority goes to games with > 10 votes and an avg rating higher than 3?
  3. Got it! SELECT `id` , `name` FROM `info` LEFT JOIN `rating` ON rating.game_id = info.id GROUP BY info.id ORDER BY ( AVG( rating.rating_value ) ) DESC Thanks for the help! Is there a way I can make it so results with < 10 votes doesn't come up first?
  4. Sort result by a different tables values I'm working on a script that shows games compiled in a MySQL database. I'm trying to sort them by highest rated. The ratings are stored in a different table. The tables are set up as follows: table `info` | id | user_id | name | desc | category | plays | date_added | table `rating` | game_id | user_id | rating_value | I think this is possible using a JOIN. I don't know much about JOIN's but it seems that it could be done. The way I'm trying to do it right now is add up the rating values for the specific ID, then divide that by the number of ratings for the specific ID, then sort the result by the highest number. I'm using this query to no avail: SELECT `id` , `name` FROM `info` JOIN `rating` AS `rating` ORDER BY ( COUNT( rating.game_id ) / SUM( rating.rating_value ) ) DESC Any help is much appreciated!
  5. As long as you validate information passed through URL query's it does not pose as a threat.
  6. You may want to look into password salting if you're concerned with security. Here is a link: http://www.richardlord.net/blog/php-password-security
  7. Set a session for the users id upon logging in, then whenever you need to pull data for the logged in user, use the session variable.
  8. I'm working on a script that shows game compiled in a MySQL database. I'm trying to sort them 3 different ways: newest, most popular, and highest rated. The first two are easy because they are in the same table as the game information. However, the ratings are stored in a different table. I think this is possible to do using a join, but I don't know how to do that. The tables are set up as follows: table `info` | id | user_id | name | desc | category | plays | date_added | table `rating` | game_id | user_id | rating_value | Is it possible to add up the rating values, then divide that by the number of ratings for the specific id, then sort the result by the highest rated game?
  9. Did someone kill it? Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13) in /mounted-storage/home48c/sub007/sc33591-LWQU/picks_web/new_kp/core/includes/db-config.php on line 11 Site Returned Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
  10. Very nice job cleaning it up. It looks great now!
  11. Haha wow, the query is wrong. I'm never going to try coding anything at 7:00am again!
  12. If you didn't notice, I used the mysql_fetch_array() function, which puts the results into variable $r, as seen in my code. The only reason my code wouldn't work is because I put two $ by accident.
  13. $r=mysql_fetch_array(mysql_query("SELECT 'Username','XP' FROM 'users' WHERE 'ID'='".$id."' ORDER BY RAND() LIMIT 1")); echo 'Username: '.$$r['username'].' XP: '.$$r['xp'];
  14. It looks good but size it down! It won't even fit on my 22" widescreen.
  15. You can use file_get_contents() and then sort through the file and get what you need using preg_match()
  16. Why can't you do this with phpmyadmin? It has an option to export to CSV.
  17. I couldn't agree more. Why on earth would you need to pass that through the URL?
  18. mysql_query("SELECT `username`,`xp` FROM `users` WHERE `id`='".$id."' ORDER BY RAND() LIMIT 1"); I'm fairly certain that would be the fastest and most efficient way.
  19. Thanks, I ended up creating two separate functions and it's working now. Thank you for the advice.
  20. I'm trying to resize an image, maintaining its aspect ratio, and then add a drop shadow to it. However, the script simply outputs a 5x5 black image. Here is the code: function thumbnail($inputFileName, $maxsize) { $info = getimagesize($inputFileName); $type = isset($info['type']) ? $info['type'] : $info[2]; $width = isset($info['width']) ? $info['width'] : $info[0]; $height = isset($info['height']) ? $info['height'] : $info[1]; // Calculate aspect ratio $wRatio = $maxSize / $width; $hRatio = $maxSize / $height; // Using imagecreatefromstring will automatically detect the file type $sourceImage = imagecreatefromstring(file_get_contents($inputFileName)); // Calculate a proportional width and height no larger than the max size. if ( ($width <= $maxSize) && ($height <= $maxSize) ) { $tHeight=$height; $tWidth=$width; } elseif ( ($wRatio * $height) < $maxSize ) { $tHeight = ceil($wRatio * $height); $tWidth = $maxSize; } else { $tWidth = ceil($hRatio * $width); $tHeight = $maxSize; } $thumb = imagecreatetruecolor($tWidth, $tHeight); imagecopyresampled($thumb, $sourceImage, 0, 0, 0, 0, $tWidth, $tHeight, $width, $height); imagedestroy($sourceImage); /* offset of drop shadow from top left */ define("DS_OFFSET", 5); /* number of steps from black to background color */ define("DS_STEPS", 10); /* distance between steps */ define("DS_SPREAD", 1); /* define the background color */ $background = array("r" => 255, "g" => 255, "b" => 255); /* create a new canvas. New canvas dimensions should be larger than the original's */ $width = $tWidth+DS_OFFSET; $height = $tHeight+DS_OFFSET; $image = imagecreatetruecolor($width, $height); /* determine the offset between colors */ $step_offset = array("r" => ($background["r"] / DS_STEPS), "g" => ($background["g"] / DS_STEPS), "b" => ($background["b"] / DS_STEPS)); /* calculate and allocate the needed colors */ $current_color = $background; for ($i = 0; $i <= DS_STEPS; $i++) { $colors[$i] = imagecolorallocate($image, round($current_color["r"]), round($current_color["g"]), round($current_color["b"])); $current_color["r"] -= $step_offset["r"]; $current_color["g"] -= $step_offset["g"]; $current_color["b"] -= $step_offset["b"]; } /* floodfill the canvas with the background color */ imagefilledrectangle($image, 0,0, $width, $height, $colors[0]); /* draw overlapping rectangles to create a drop shadow effect */ for ($i = 0; $i < count($colors); $i++) { imagefilledrectangle($image, DS_OFFSET, DS_OFFSET, $width, $height, $colors[$i]); $width -= DS_SPREAD; $height -= DS_SPREAD; } /* overlay the original image on top of the drop shadow */ imagecopymerge($image, $thumb, 0,0, 0,0, $tWidth, $tHeight, 100); imagedestroy($thumb); return $image; } Any help is greatly appreciated!
  21. I'm using code from this project: getID3 Here is the code: require_once('/var/www/getid3/getid3.php'); $getid3 = new getID3; $file=$_FILES['file']['tmp_name']; $id3 = $getid3->analyze($file); getid3_lib::CopyTagsToComments($id3); $cbr=($id3['audio']['bitrate_mode'] == 'cbr') ? ' CBR' : ''; $id3['audio']['bitrate']=round($id3['audio']['bitrate']/1000).'kbps'.$cbr; $length=explode(':',$id3['playtime_string']);
  22. You're welcome, glad to help.
  23. Does functions.php have <?php ?> tags?
×
×
  • 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.