Jump to content

Gibbs

Members
  • Posts

    63
  • Joined

  • Last visited

    Never

Everything posted by Gibbs

  1. I have done this before but not in PHP. I don't think it would be possible in PHP unless you are allowed to use some dangerous functions such as exec. That would still rely on external software though.
  2. The idea is that it keeps generating passwords (or in this case tokens) until it finds a unique one. Excellent. That makes a lot more sense! Thanks.
  3. You have two main options off the top of my head. You can base64 encode the image an put it directly into the HTML document. This is perfectly acceptable for small images. <?php // Not tested $image = base64_encode($row['image']); $output = 'data:image/jpg;base64,' . $image; ?> <img src="<?php echo $output ?>" /> Or you will have to create a separate script and set the content type in a header. Then you would link to the script in the src attribute. <?php // Not tested $image = $row['image']; header("Content-type: image/jpg"); echo $image; Or you could write the image to the filesystem, which I doubt you want to do.
  4. Apart from the fact this can cause an infinite loop is it OK to use? $user->reset_token = $user->generate_password(32); // Make sure the token is unique while(TRUE) { $count = ORM::factory('manager')->where('reset_token', '=', $user->reset_token)->count_all(); if($count < 1) break; $user->reset_token = $user->generate_password(32); } Or would you approach the logic for this differently? Thoughts appreciated. Cheers
  5. I'm trying to find the two largest values in an array. The max function is great but I'm also looking for the second largest number... I can't use any sorting functions as the array name must stay the same. The sort functions I've tried, for example, will rename $array["TEST1"] to $array[0]. Any help appreciated. Thanks.
  6. Thanks for the help. Managed to come up with this. Still long but cuts the code down. <?php for ($x = 0; $x < 8; $x++) { $sectSel = "LLL"; switch($x) { case 0: $partSearch = "LLL"; break; case 1: $partSearch = "FFF"; break; case 2: $partSearch = "GGG"; break; case 3: $partSearch = "BBB"; break; case 4: $partSearch = "MMM"; break; case 5: $partSearch = "CCC"; break; case 6: $partSearch = "EEE"; break; case 7: $partSearch = "VVV"; break; } if ($arrayData[sect][$sectSel][0][$partSearch] == "E") { $eString[$sectSel] = $eString[$sectSel]." ".$partSearch; } } echo $eString[$sectSel]; ?>
  7. Array ( [sect] => Array ( [LLL] => Array ( [0] => Array ( [CCC] => A [FFF] => A [VVV] => A [GGG] => A [EEE] => A [MMM] => E [bBB] => E ) ) [FFF] => Array ( [0] => Array ( [LLL] => A [GGG] => A [bBB] => N [MMM] => E [CCC] => N [EEE] => A [VVV] => A) ) That's an example of the array. I'm guessing its four-dimension? Using the first part for LLL I need to echo the value of each (if it equals A) arrays value (like CCC) as well as the array name CCC. The output would need be something like: A CCC A FFF A VVV A GGG A EEE
  8. I haven't got any experience with most array functions so I'm finding it difficult to be creative. Anyway... I have an array that has multiple arrays inside it. I'm trying to find the value of each array. The problem is that I also need to know the name of the array that is in use. Heres an example of what I'm doing: if ($arrayData[sect][TEX][0][AAA] == "A") { $ret_a = $ret_a."AAA "; } if ($arrayData[sect][TEX][0][GGG] == "A") { $ret_a = $ret_a."GGG "; } if ($arrayData[sect][TEX][0][bBB] == "A") { $ret_a = $ret_a."BBB "; } if ($arrayData[sect][TEX][0][MMM] == "A") { $ret_a = $ret_a."MMM "; } if ($arrayData[sect][TEX][0][CCC] == "A") { $ret_a = $ret_a."CCC "; } if ($arrayData[sect][TEX][0][EEE] == "A") { $ret_a = $ret_a."EEE "; } if ($arrayData[sect][TEX][0][VVV] == "A") { $ret_a = $ret_a."VVV "; } That's a lot of code especially as I have to find out B, C and search another 7 of these. I'm probably not making any sense whatsoever but it's difficult to explain. Basically I need to find out all the arrays inside $arrayData[sect][TEX][0], find it's value AND return the name of that array. This is being done from a live feed so I can't change the XML file unfortunately. I can do this but 147 lines is a waste of time... Any help appreciated!
  9. You can check if the file exists by using the file_exists function prior to uploading. Never done this so I can't be 100% sure. With the move_uploaded_file function you can specify the path. For example: move_uploaded_file($_FILES['upfile']['name'],<where you want it/filename>)
  10. I know it can be made shorter but that doesn't help. The game time is 4 times faster then ours so 1 day is 4 days in the game. To calculate that you need to calculate the amount of time lapsed from X date to current date * 4. I'll have a play around with it though. Cheers.
  11. Don't get me wrong (my PHP is appalling on some functions) but I think I need a specific format for this to work?
  12. To calculate the year I've made an integer without using the mktime function. I don't think that's the problem as I have "2405" being printed locally and remotely on a PHP 5 server. I've checked the date and time config on the server and it's correct (except 4 hours behind). I've altered the script to suit that as the PHP 5 server was also 4 hours behind. $fom_year = 2404 + (2007 - 2007); doesn't equal 2367. Confused...
  13. Nevermind. Can't keep up with gurus...
  14. Your trying to loop a query to output multiple results? Why not use: $q = mysql_query(your query); while ($r = mysql_fetch_array($q)) { // Do this }
  15. Hello! I'm attempting to calculate the date for an online game that's set in the future. The games time is 4 times faster then our time so to figure it out I recorded the exact date/time in the game and the exact date/time in real time. Then all I need to do is multiply the seconds by 4 to the fictional date. Here is what I currently have: $realTime_start = mktime(17, 44, 20, 9, 25, 2007); $realTime_current = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y")); $fomTime_start = mktime(14, 57, 0, 12, 8, 2007); $seconds = ($realTime_current - $realTime_start) * 4; $fom_date_full = date("H:i jS F Y",(strtotime("14:57 8 December 2007") + ($seconds))); $fom_year = substr($fom_date_full, (strlen($fom_date_full) - 4), strlen($fom_date_full)); $fom_year = 2404 + ($fom_year - 2007); $fom_date = date("H:i jS F",(strtotime("14:57 8 December") + ($seconds))); $fom_date_full = $fom_date." ".$fom_year; This works perfect in PHP 5+ but not on a server I'm using at the moment for testing (which uses PHP 4.4.4). I've referred to the manual to check the functions haven't changed from these versions and by the look there hasn't been any major changes. At the time of writing this the correct output is "22:18 17th January 2405" and the PHP 4 output is "02:17 10th February 2367". I would be grateful for any help, it's starting to hurt my brain Thanks
  16. If they're ALL The (for example The English, The French etc) then the below *should* work. You will need to change 15 to the longest string you have. For example The English (if that's your longest word) would be 5, 7. The first number is where you want the string starts, the second is the length to be extracted. SELECT SUBSTRING(`yourfield`, 5, 7) + 0 AS nationality, tb.* FROM `yourtable` tb ORDER BY nationality ASC Something like $query = mysql_query("SELECT SUBSTRING(`yourfield`, 7, 15) + 0 AS nationality, tb.* FROM `yourtable` tb ORDER BY nationality DESC"); while ($result = mysql_fetch_array($query)) { echo "$result[yourfield]<br />"; }
  17. I don't fully understand them in MySQL but if you don't get any useful replies (which is doubtful ) look up using SUBSTRING. Do they ALL have "The"? If so it would probably be easier...
  18. In PHP you can use strlen to get the length of a string. If your input is part of a form you could use strlen to check the length of your string. For example: <?php $myvar = 'this is some text to test'; if (strlen($myvar) >= 15) { // Do this if too long echo "String too long!"; } else { // Do this is fine echo "String is fine!"; } ?> Edit: Ah, got beaten to it!
  19. SUBSTR didn't work but it worked perfect with SUBSTRING. Thank you!
  20. I have values like this in my database: VTXH001/80 VTXD002/95 VTXD003/95 VTX > Letter of second name > Issue Number > Result. So if your name is Mr Smith and you scored 60 it would be VTXS004/60 My problem is that I need to order them by the 001/002/003 (etc) part. Is it possible to search through the whole result and order it by a certain part? I hope that makes sense and thanks for any help.
  21. That's brilliant. I was actually thinking about for loops, havent used them for years though and completely forgot the method for them. Thanks!  ;D
  22. I'm looking for a better way to achieve what i'm trying to do... At the moment I have a database entry that is a number below 5. I want to echo something the same amount of times the number is. So if the number is 1 then it draws one picture, if it's 2 then two pictures. Now what I'm doing works, don't get me wrong, but surely there is a better and less time consuming method then what is being done below? [code=php:0]if ($resulta['demerits'] == 1) { echo "<td width=\"18\"><img src=\"img/icons/demerit.jpg\" border=\"0\"></img></td>"; } elseif ($resulta['demerits'] == 2) { echo "<td width=\"18\"><img src=\"img/icons/demerit.jpg\" border=\"0\"></img></td>"; echo "<td width=\"18\"><img src=\"img/icons/demerit.jpg\" border=\"0\"></img></td>"; }[/code] Thanks for any replies :D
  23. PFF!!!! I never knew that  ??? That's brilliant and thanks. I've learnt three new things in PHP today. And jesirose you've helped me out previously before. I really do appreciate it! Thank you  ;D
×
×
  • 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.