-
Posts
969 -
Joined
-
Last visited
Everything posted by Destramic
-
im trying to make a simple template engine but am having a problem replacing the string in the content....if anyone could give me any help or pointers please <?php class Template { public function display($filename) { echo "hello"; } public function assign($variable, $value) { if (!is_array($value)) { ob_start(); $contents = ob_get_contents(); $contents = str_replace($variable, $value, $contents); ob_end_clean(); return $contents; } } } $template = new Template(); $template->display(); $template->assign("hello", "test"); ?> code above will only display hello and not test as it should
-
hey guys i have an if statement and if it returns false then i want it to change to variable values....something like this but it doesn't work IF(@points = '0', @rank + 1, @rank @drawing = '1') can anyone tell me how this is possible please
-
sorry i got it working now....its not returning the rank correctly as it should ( [0] => 2 [team_id] => 2 [1] => JAG [team_name] => JAG [2] => 2 [matches_played] => 2 [3] => 1 [wins] => 1 [4] => 1 [losses] => 1 [5] => 0 [draws] => 0 [6] => 3 [points] => 3 [7] => 1 [@rank := IF(@points=points, @rank, @rank+1)] => 1 [8] => 3 [@points:=points] => 3 ) <tr> <td> <img src="/images/arrow_down_red.gif" height="16" width="16" alt="hey"></td> <td><img src="/images/countrys/united_kingdom.gif" height="15" width="21"> JAG</td> <td>2</td> <td>1</td> <td>1</td> <td>0</td> <td>0</td> <td>3</td> </tr> Array ( [0] => 1 [team_id] => 1 [1] => SAS [team_name] => SAS [2] => 1 [matches_played] => 1 [3] => 1 [wins] => 1 [4] => 0 [losses] => 0 [5] => 0 [draws] => 0 [6] => 3 [points] => 3 [7] => 2 [@rank := IF(@points=points, @rank, @rank+1)] => 2 [8] => 3 [@points:=points] => 3 ) both teams should be ranked 1 becasue of being both on 3 points
-
sasa its coming back with an error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':1 GROUP BY t.team_id ORDER BY points,' at line 13 do you know why please? but when i run the query in phpmyadmin it executes fine
-
thank you sasa that worked great thank you...now there is just one more problem i have...if a team has the same points then i want the rank to stop counting so the ranking order would be the same....example rank name pts 1 team 1 10 1 team 2 10 instead of it looking like rank 1,2 $team_select = "SELECT @rank := @rank + 1 AS 'rank', t.team_id, t.team_name, COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win',1,0)) AS `wins`, SUM(IF(r.result='Loss',1,0)) AS `losses`, SUM(IF(r.result='Draw',1,0)) AS `draws`, SUM(IF(r.result='Win',3,IF(r.result='Draw',1, IF(r.result='Loss',0,0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id RIGHT JOIN league_matches m ON r.league_match_id = m.league_match_id WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY team_name"; is this possible?
-
anyone know how i can calculate my wins and draw columns and save as points column please?
-
hey sasa thanks for your reply...erm but what i need is to have a sum of all the wins and then times by 3....something like SUM(wins * 3) + SUM(draws * 1) AS `points` but i dont know how
-
hey guys im trying to make a league website and below the query calculates the wins losses and draws of a team in each row what i want in this query is to make a points column which will add all the wins losses and draws up all together win = 3 pts draw = 2 pts loss = 0 pts so if a team has won a game and drawn a game the points colum will be 5...i hope this explains what i want...is this possible please? $team_select = "SELECT @rank := @rank + 1 AS 'rank', t.team_id, t.team_name, COUNT(r.league_match_result_id) AS 'matches_played', COUNT(CASE r.result WHEN 'Win' THEN '3' END) AS 'wins', COUNT(CASE r.result WHEN 'Loss' THEN '0' END) AS 'losses', COUNT(CASE r.result WHEN 'Draw' THEN '1' END) AS 'draws' FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id RIGHT JOIN league_matches m ON r.league_match_id = m.league_match_id WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY team_name";
-
ive added SET @rank := 0; and @rank := @rank + 1 AS rank, to my query and it now comes back with errors because of this and i dont see why...can someone please explain why its not working MySQL Error #1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT @rank := @rank + 1 AS rank, t.team_id, ' at line 2. SET @rank := 0; SELECT @rank := @rank + 1 AS rank, t.team_id, t.team_name, COUNT(r.league_match_result_id ) AS 'matches_played', COUNT(CASE r.result WHEN 'Win' THEN '3' END) AS 'wins', COUNT(CASE r.result WHEN 'Loss' THEN '0' END) AS 'losses', COUNT(CASE r.result WHEN 'Draw' THEN '1' END) AS 'draws' FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id LEFT JOIN league_matches m ON r.league_match_id = m.league_match_id WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY wins DESC, draws DESC, losses DESC
-
but that means every column in the teams table would have to be updated everytime a team goes up/down the ladder...isnt there something i can do query wise?
-
i have a query that selects a number of teams ordered by they're results and also have a variable called $rank which generates the teams rank just from a simple loop...but the problem i have is if i order the query by another column (team_name) then the rank will stay the same but obviosuly the query result order will change...what i need/want to know is how it is possible to change the order of the query but still keep the correct rank number for each team please? <?php $document_root = $_SERVER['DOCUMENT_ROOT']; require_once $_SERVER['DOCUMENT_ROOT'] . "\classes\MySQL.php"; $league_id = $_GET['league_id']; $team_select = "SELECT t.team_id, t.team_name, COUNT(r.league_match_result_id ) AS 'matches_played', COUNT(CASE r.result WHEN 'Win' THEN '3' END) AS 'wins', COUNT(CASE r.result WHEN 'Loss' THEN '0' END) AS 'losses' COUNT(CASE r.result WHEN 'Draw' THEN '1' END) AS 'draws' FROM teams t LEFT JOIN league_match_results r ON t.team_id = r.team_id LEFT JOIN league_matches m ON r.league_match_id = m.league_match_id WHERE m.league_id = :1 GROUP BY t.team_id ORDER BY wins DESC, draws DESC, losses DESC"; $mysql = new MYSQL(); $team_result = $mysql->prepare($team_select); $team_result->execute($league_id); $team_count = $team_result->num_row_count(); ?> <table> <tr> <th>Rank</th> <th>Team</th> <th>MP</th> <th>W</th> <th>L</th> <th>D</th> <th>Streak</th> <th>PTS</th> </tr> <?php $rank = 1; while ($team_row = $team_result->fetch_array()) { $team_id = $team_row['team_id']; $team_name = $team_row['team_name']; $matches_played = $team_row['matches_played']; $wins = $team_row['wins']; $losses = $team_row['losses']; $draws = $team_row['draws']; $points = ($wins * 3) + ($draws * 1) + ($losses * 0); echo " <tr>\n"; echo " <td>" . $rank . "</td>\n"; echo " <td>" . $team_name . "</td>\n"; echo " <td>" . $matches_played . "</td>\n"; echo " <td>" . $wins . "</td>\n"; echo " <td>" . $losses . "</td>\n"; echo " <td>" . $draws . "</td>\n"; echo " <td>"-"</td>\n"; echo " <td>" . $points . "</td>\n"; echo " </tr>\n"; $rank ++; } ?> </table>
-
thanks alot again...also one last thing when i processing these results is it good practice to do it with <div> and styles or just do it using a <table>?
-
ive been trying to work it out mysql and ive got it working but im not sure if this is the best way....im new to the case statement so this might be a bit long winded if you could help SELECT t.team_id, t.team_name, COUNT( r.league_match_result_id ) AS 'team_matches_played', COUNT( CASE r.result WHEN 'Win' THEN 'team_wins' END ) AS 'team_wins', COUNT( CASE r.result WHEN 'Draw' THEN 'team_draws' END ) AS 'team_draws', COUNT( CASE r.result WHEN 'Loss' THEN 'team_losses' END ) AS 'team_losses' FROM teams t LEFT JOIN league_match_results r ON t.team_id = r.team_id GROUP BY t.team_id ORDER BY team_wins DESC, team_draws DESC
-
thanks jcbones...what i need the sum of the win draws and losses (like SUM(r.win) AS team_wins)....and this way i can order the query by wins, losses and draws asscendingly to get the correct results please
-
i think this is almost what i need...the result will contain three values....win...loss...draw so i need to count these three and then order by them instead of just counting result....is this possible please wildteen
-
hey guys i have two tables called teams and results and basically the the results table will store the results of each match the team has. what i need to do is when i select all the teams i need the team with the most results to be ordered first and descending from there....example ------------------ man united 12 pts liverpool 9 pts etc etc ------------------ the tables im using are below if anyone could tell me the best way of calculating the results and ordering them please...thank you teams ------------- team_id team_name ------------- results ------------- result_id team_id result -------------
-
is there a way of finding out how much time is left on a cookie please? thanks desrtramic
-
hey guys im making a auth class and im wondering wheather it is best to use session_set_cookie_params or setcookie to remember the users state....just a quick question if anyone could tell me what the real difference is and which one would be the best to use...thank you
-
well thanks you all for your advise it been very helpful...and im thinking i going to have a column in my database storing the session id and having a cookie storing the same id if the user wants to be remembered...and that will be my key thank you again
-
thanks that worked great....is there also a way of getting a border when having a transparent background?
-
ive tried to set the transparentcey but its not working...also i think im having a problem with text and border colour <?php function image_captcha_verification($width = NULL, $height = NULL, $words = NULL) { $font_size = "18"; $border_colour = "239, 239, 239"; $font = "verdana.ttf"; $width = "400"; $height = "80"; $words = array ("police", "time", "broadway", "is", "throughout", "hateful", "action", "duvet", "tailcoat", "the", "danger", "minster", "army", "dent", "share", "beard", "lazy", "year", "must", "resigned", "angry", "relapse", "trump", "union", "adventure", "honey", "inject", "special", "end", "crossing", "slow", "grunge", "prize", "of", "dreamer", "issues", "tomcat", "riverbed", "founder", "working", "mask", "spinned", "reported", "meets", "john", "by", "vogue", "said", "jumpy", "democratic", "kingdom", "combs", "moments", "peaks", "rise", "innocent", "chalked", "from", "relations", "removing", "platform", "unwillingness", "secretary", "computer", "arranger", "mentor", "was", "quote", "warn", "rally", "squadron", "profiles", "immature", "in", "drives", "train", "intrude", "state", "defense", "past", "plunges", "cry", "cameras", "promises", "outskirt", "subtitles", "hidden", "logic", "advertisement", "exact", "dimond", "risk", "director", "back", "sinatra", "store", "stopgap", "equal", "housing", "airport", "him", "security", "one", "dodges", "development", "entertainer", "ignition", "lovebird", "counts", "world", "protocol", "than", "cry", "shannon", "shear", "drain", "blues", "morning", "fronting", "executive", "person", "reached", "taxplayer", "stranger", "schedules", "preston", "historic", "featured", "port", "tricked", "announced", "can", "time", "loadable", "wallets", "wounded", "core", "empire", "towers", "wished", "confused", "who", "hurdles", "toggles", "martin", "defender", "plane", "decked", "but", "harp", "ribs", "helpers", "least", "column", "cement", "room", "tension", "clipper", "shudder", "dangles", "storm", "farms", "zero", "affairs", "maniacs", "proposals", "two", "surrounded", "bone", "difficult", "dusters", "sailed", "bonding", "speak", "however", "sands", "scribble", "maiden", "mouths", "arms", "coopered", "learned", "recieved", "rocks", "tripod", "skull", "dwarf", "number", "arrested", "squish", "singer", "buttered", "found", "new", "million", "token", "combo", "completed", "national", "markets", "because", "lower", "trainers", "chief", "angle", "seabed", "trickled", "firsy", "undated", "ludlow", "stones", "joker", "monster", "reach", "outlook", "aware", "among", "comfort", "living", "contact", "french", "thailand", "open", "yelps", "delayed", "smart", "metropolitan", "meter", "snow", "castle", "tools", "irrigration", "new", "gas", "sidestepping", "drys", "cartoons", "declared", "numskull", "brass", "sped", "washington", "landing", "ordeal", "cops", "quiet", "strike", "destruct", "wrote", "mamma", "tunes", "balanced", "officers", "books", "flame", "am", "fishing", "not", "inspires", "beehives", "hypnotic", "flops", "sandhurst", "invoked", "bullion", "christmas", "muttered", "moats", "baggy", "ginger", "obligated", "hangover", "building", "midland", "mocks", "heavy", "don", "quotable", "clarkson", "vary", "enriches", "romania", "sumo", "ushering", "votes", "cool", "resumed", "sprayers", "convents", "unchanging", "prove", "renshaw", "holy", "recited", "kingpins", "valiant", "yesterday", "withdrawel", "itself", "slog", "marry", "newborns"); $image = imagecreatetruecolor($width, $height); $background = imagecolorallocatealpha($image, 255, 0, 0, 0); $text = imagecolorallocate($image, 20, 40, 100); imagefill($image, 0, 0, $background); imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $border_colour); imagecolortransparent($image, $background); $random_key = array_rand($words, 2); $string = $words[$random_key[0]] . " " . $words[$random_key[1]]; $array = preg_split("//", $string, -1); $array_length = count($array) - 1; for($i = 1; $i < $array_length; $i++) { $letter = $array[$i]; if ($letter == " ") { // ucfirst //lcfirst //strtolower //strtoupper //ucwords } $letter_spacer = 25 * $i; $angle = rand(1, 25); $x_coordinates = 50 + $letter_spacer; $y_coordinates = ($height / 2); imagettftext($image, $font_size, $angle, $x_coordinates, $y_coordinates, $text_colour, $font, $letter); } session_start(); $_SESSION['captcha_code'] = md5($string); header("Content-type: image/png"); imagepng($image); imagedestroy($image); } image_captcha_verification(); ?>
-
thanks alex that was the problem thanks...now the other problem im having is that the background is black on the image and i cant see no text idealy i need the image to be transparant if possible <?php function image_captcha_verification() { $font_size = "14"; $border_colour = "239, 239, 239"; $background_colour = "255, 255, 255, 127"; $text_colour = "191, 120, 120"; $font = "verdana.ttf"; $width = "350"; $height = "80"; $words = array ("police", "time", "broadway", "is", "throughout", "hateful", "action", "duvet", "tailcoat", "the", "danger", "minster", "army", "dent", "share", "beard", "lazy", "year", "must", "resigned", "angry", "relapse", "trump", "union", "adventure", "honey", "inject", "special", "end", "crossing", "slow", "grunge", "prize", "of", "dreamer", "issues", "tomcat", "riverbed", "founder", "working", "mask", "spinned", "reported", "meets", "john", "by", "vogue", "said", "jumpy", "democratic", "kingdom", "combs", "moments", "peaks", "rise", "innocent", "chalked", "from", "relations", "removing", "platform", "unwillingness", "secretary", "computer", "arranger", "mentor", "was", "quote", "warn", "rally", "squadron", "profiles", "immature", "in", "drives", "train", "intrude", "state", "defense", "past", "plunges", "cry", "cameras", "promises", "outskirt", "subtitles", "hidden", "logic", "advertisement", "exact", "dimond", "risk", "director", "back", "sinatra", "store", "stopgap", "equal", "housing", "airport", "him", "security", "one", "dodges", "development", "entertainer", "ignition", "lovebird", "counts", "world", "protocol", "than", "cry", "shannon", "shear", "drain", "blues", "morning", "fronting", "executive", "person", "reached", "taxplayer", "stranger", "schedules", "preston", "historic", "featured", "port", "tricked", "announced", "can", "time", "loadable", "wallets", "wounded", "core", "empire", "towers", "wished", "confused", "who", "hurdles", "toggles", "martin", "defender", "plane", "decked", "but", "harp", "ribs", "helpers", "least", "column", "cement", "room", "tension", "clipper", "shudder", "dangles", "storm", "farms", "zero", "affairs", "maniacs", "proposals", "two", "surrounded", "bone", "difficult", "dusters", "sailed", "bonding", "speak", "however", "sands", "scribble", "maiden", "mouths", "arms", "coopered", "learned", "recieved", "rocks", "tripod", "skull", "dwarf", "number", "arrested", "squish", "singer", "buttered", "found", "new", "million", "token", "combo", "completed", "national", "markets", "because", "lower", "trainers", "chief", "angle", "seabed", "trickled", "firsy", "undated", "ludlow", "stones", "joker", "monster", "reach", "outlook", "aware", "among", "comfort", "living", "contact", "french", "thailand", "open", "yelps", "delayed", "smart", "metropolitan", "meter", "snow", "castle", "tools", "irrigration", "new", "gas", "sidestepping", "drys", "cartoons", "declared", "numskull", "brass", "sped", "washington", "landing", "ordeal", "cops", "quiet", "strike", "destruct", "wrote", "mamma", "tunes", "balanced", "officers", "books", "flame", "am", "fishing", "not", "inspires", "beehives", "hypnotic", "flops", "sandhurst", "invoked", "bullion", "christmas", "muttered", "moats", "baggy", "ginger", "obligated", "hangover", "building", "midland", "mocks", "heavy", "don", "quotable", "clarkson", "vary", "enriches", "romania", "sumo", "ushering", "votes", "cool", "resumed", "sprayers", "convents", "unchanging", "prove", "renshaw", "holy", "recited", "kingpins", "valiant", "yesterday", "withdrawel", "itself", "slog", "marry", "newborns"); $image = imagecreate($width, $height); $background = imagecolorallocatealpha($image, 255, 255, 255, 127); $text = imagecolorallocate($image, 20, 40, 100); imagefill($image, 0, 0, $background); imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $border_colour); $string = "test 123!"; $angl = "5"; $x_coordinates = "24"; $y_coordinates = "24"; imagettftext($image, $font_size, $angle, $x_coordinates, $y_coordinates, $text_colour, $font, $string); header("Content-type: image/png"); imagepng($image); imagedestroy($image); } image_captcha_verification(); ?>
-
hey guys im trying to make an image captcha script for the fisrt time im having a problem getting it to work...its returning Fatal error: Call to undefined function imagecreate() in C:\www\functions\captcha _image_verification.php on line 41 does anyone know why...im sure im using the right syntex <?php function image_captcha_verification() { $font_size = "14"; $border_colour = "239, 239, 239"; $background_colour = "255, 255, 255, 127"; $text_colour = "191, 120, 120"; $font = "verdana.ttf"; $width = "100"; $height = "100"; $words = array ("police", "time", "broadway", "is", "throughout", "hateful", "action", "duvet", "tailcoat", "the", "danger", "minster", "army", "dent", "share", "beard", "lazy", "year", "must", "resigned", "angry", "relapse", "trump", "union", "adventure", "honey", "inject", "special", "end", "crossing", "slow", "grunge", "prize", "of", "dreamer", "issues", "tomcat", "riverbed", "founder", "working", "mask", "spinned", "reported", "meets", "john", "by", "vogue", "said", "jumpy", "democratic", "kingdom", "combs", "moments", "peaks", "rise", "innocent", "chalked", "from", "relations", "removing", "platform", "unwillingness", "secretary", "computer", "arranger", "mentor", "was", "quote", "warn", "rally", "squadron", "profiles", "immature", "in", "drives", "train", "intrude", "state", "defense", "past", "plunges", "cry", "cameras", "promises", "outskirt", "subtitles", "hidden", "logic", "advertisement", "exact", "dimond", "risk", "director", "back", "sinatra", "store", "stopgap", "equal", "housing", "airport", "him", "security", "one", "dodges", "development", "entertainer", "ignition", "lovebird", "counts", "world", "protocol", "than", "cry", "shannon", "shear", "drain", "blues", "morning", "fronting", "executive", "person", "reached", "taxplayer", "stranger", "schedules", "preston", "historic", "featured", "port", "tricked", "announced", "can", "time", "loadable", "wallets", "wounded", "core", "empire", "towers", "wished", "confused", "who", "hurdles", "toggles", "martin", "defender", "plane", "decked", "but", "harp", "ribs", "helpers", "least", "column", "cement", "room", "tension", "clipper", "shudder", "dangles", "storm", "farms", "zero", "affairs", "maniacs", "proposals", "two", "surrounded", "bone", "difficult", "dusters", "sailed", "bonding", "speak", "however", "sands", "scribble", "maiden", "mouths", "arms", "coopered", "learned", "recieved", "rocks", "tripod", "skull", "dwarf", "number", "arrested", "squish", "singer", "buttered", "found", "new", "million", "token", "combo", "completed", "national", "markets", "because", "lower", "trainers", "chief", "angle", "seabed", "trickled", "firsy", "undated", "ludlow", "stones", "joker", "monster", "reach", "outlook", "aware", "among", "comfort", "living", "contact", "french", "thailand", "open", "yelps", "delayed", "smart", "metropolitan", "meter", "snow", "castle", "tools", "irrigration", "new", "gas", "sidestepping", "drys", "cartoons", "declared", "numskull", "brass", "sped", "washington", "landing", "ordeal", "cops", "quiet", "strike", "destruct", "wrote", "mamma", "tunes", "balanced", "officers", "books", "flame", "am", "fishing", "not", "inspires", "beehives", "hypnotic", "flops", "sandhurst", "invoked", "bullion", "christmas", "muttered", "moats", "baggy", "ginger", "obligated", "hangover", "building", "midland", "mocks", "heavy", "don", "quotable", "clarkson", "vary", "enriches", "romania", "sumo", "ushering", "votes", "cool", "resumed", "sprayers", "convents", "unchanging", "prove", "renshaw", "holy", "recited", "kingpins", "valiant", "yesterday", "withdrawel", "itself", "slog", "marry", "newborns"); $image = imagecreate($width, $height); $background = imagecolorallocatealpha($image, $background_colour); $text = imagecolorallocate($image, $text_colour); imagefill($image, 0, 0, $background); imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $border_colour); $string = rand($words); $angl = "5"; $x_coordinate = "24"; $y_coordinate = "24"; imagettftext($image, $font_size, $angle, $x_coordinate, $y_coordinate, $text_colour, $font, $string); header("Content-type: image/png"); imagepng($image); imagedestroy($image); } image_captcha_verification(); ?>
-
so basically you saying if the user wants thier details to be remembers we will set a cookie with the user id so that when the user comes back to the website there will be a live cookie with the user id and that will mean the user is suppose to be logged in? sorry i just wanna makesure i understand
-
well thanks for your replay...but regarding using a session instead of a cookie...the problem i see with that is that the session doesnt have a life like a cookie