Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Well it should be fairly easy to modify an existing tool-tip script to use some AJAX to load the text from the database. That is, of course, assuming you're familiar with AJAX. If not, then I'd suggest you either start with some basic tutorials or search for AJAX-based tool-tips.
  2. No. Why should it be? I would say that depends on what you mean by 'cheating'. If you're doing work for a paying client and they have specifically asked for a custom-made solution, then yes, you are cheating your customer. Or, if this is a project for a course and you've been requested to write everything yourself then yes, you are cheating. Otherwise, it cannot really be cheating. You're simply selecting the correct tool for the job rather than re-inventing the wheel. What's so bad about that? That would entirely depend on the license under which the library was released and how you use it. You may find, for example, that the code is free to use for non-commercial purposes. Or, alternatively, that you can use it in any way you like as long as you maintain a link on your website/a copyright notice in the code. You'll have to check the documentation of the library.
  3. I'm not 100% sure i follow your question, but it sounds like you might be after a user sort: usort (or, if you need to maintain associativity, which i think you might, uasort)
  4. Well given that it's the exact same query i posted, i'd say so Don't forget to mark as solved.
  5. Well you'll then need ORDER BY and LIMIT clauses: SELECT COUNT(*) as cnt, username FROM yourtable GROUP BY username ORDER BY cnt DESC LIMIT 5
  6. Well i can't see anything in particular that looks odd at first glance. My first suggestion would therefore be to check the lengths of the relevant fields in your database to ensure that no truncation is going on at any point.
  7. This isn't really a PHP question then is it? It's a MySQL question. You'd want a GROUP BY clause, rather than a WHERE clause: SELECT COUNT(*) as cnt, username FROM yourtable GROUP BY username And by the by, when you said you're storing the "their username and id" I assume you mean the user's personal id? In which case, you shouldn't be storing the username and id really -- it's a bit of a waste. You'd be better off storing just the id and selecting the username with a join.
  8. I don't actually see the line i recommended you to take out in the code on that site. However, i'd personally recommend the tutorials on the main site here: www.phpfreaks.com/tutorials. You'll find an excellent tutorial on basic database handling here.
  9. You need to remove this line: $row = mysql_fetch_array($result) or die(mysql_error()); As the manual page says, the function returns the next row in the result set and advances the internal pointer. So before your loop runs, you're already pointing at the second row in the result set. Edit: I shall move this topic to the FAQ/Code snippet repository once you've seen it and marked it solved. It's a fairly frequent question -- i guessed the question and answer from your title.
  10. That would be because you're seeding the random number generator each time the loop runs. The time function returns the number of seconds since 1st January 1970 (Unix Epoch) and since the the loop will take under 1 second to run, it gets seeded with the same number each time. If you're not sure why this is a problem I suggest reading up about pseudo-random numbers. The solution? Assuming you're using a version of PHP greater than 4.2.0, you don't need to seed at all because, as the manual page says, it's done automatically. Using an antiquated version? Then you just seed once prior to the loop running.
  11. I fail to see what's wrong. Surely 2000 + 3000 is 5000 and, similarly, 5 - 4000 is -3995 ?
  12. Well if the cms class is intended to work on a template object, perhaps you better give it one to work with? A rough example: <?php class foo{ private $var; function __construct($default){ $this->var = $default; } function getVar(){ return $this->var; } } class bar{ private $foo; function __construct($foo){ $this->foo = $foo; } function getFoo(){ return $this->foo; } } $foo = new foo("some value"); $bar = new bar($foo); echo $bar->getFoo()->getVar(); // echo's some value
  13. 1.) Don't double post. I moved your original topic to the correct place for the question. 2.) Use appropriate titles for your topics. You're obviously at least partially capable of this, given your previous topic. The original can be found here: http://www.phpfreaks.com/forums/index.php/topic,261262.0.html
  14. You can use Javascript to test the user's data prior to submission, but this should be used only to make things more user-friendly; you must check all data server-side too. If you google for javascript alert boxes and javascript form checking then you'll find what you need, whilst you can use the strlen fuction to test the length of the username in your PHP script (after trimming any whitespace i'd imagine).
  15. What, you mean you don't write all your programs in machine code?!
  16. Don't he cast E to ord(E)=69 and use that to compare it to 0? $txnResponseCode != 0 thus 69 != 0 => true No. This code: $var = (int) "E"; var_dump($var); $var = (float) "E"; var_dump($var); Produces: int(0) float(0) The reason I cast it to both an integer and a float is because the string contains the character 'E'. Any strings containing e, E, or '.' are converted to a float prior to comparison with a numeric value. See this page: http://us2.php.net/manual/en/language.types.string.php#language.types.string.conversion
  17. The reason for this behavior is because, as the manual page says: If you cast 'E' as an integer, it is 0. Edit: Holdup. I think i read this wrong. Edit again: No, i didn't.
  18. You don't need to use eval: $POINT = "foobar"; Function foobar($how_bar) { Echo "not just foobar, $how_bar foobar."; } $POINT('really'); However, next time you have a homework question, I suggest you present it as such. People will still help you, as long as you're not after a direct solution.
  19. Are you asking how to create a select box? If so, i'd recommend w3School's tutoral: http://www.w3schools.com/TAGS/tag_Select.asp
  20. No. Using the referrer for anything other than information gathering purposes is a bad idea imo. Some firewalls have been known to block the sending of the referrer. You shouldn't do anything to block bots that could legitimate users. Not particularly. Yes, you could add some salt to the input for any given hashing algorithm to allow it to produce a different output, but what would be the point? If you're attempting one of these token things whereby there is a hidden field in the form containing a hash which is also set in the session then sure, it makes things harder for a malicious user; but it is not fool proof.
  21. Well you've been shown how to do the first part...though you might wish to have the constructor of your class call the function if you don't wish to call it explicitly each time: class foo{ private $fields = array(); function __construct(){ echo "html {$this->getVar()}" . "\n"; $this->setFields(); } private function setFields() { global $database; $sql = "SHOW FIELDS FROM ".self::$table_name; $result_set = $database->query($sql); while ($row = $database->fetch_array($result_set)) { $this->fields[] = $row[0]; } } } Obviously that method wont work if you're really wanting a public static function. But do you? As for question two, why would you want to do this?
  22. As I understand your question, The Little Guy answered it correctly. So if you're not actually wanting the function to return an array containing all the field names, then you're going to have to re-explain yourself.
  23. You can't do anything like that. The browser needs to be able to make a request to /process/action.php in order to submit the form. Yes, you can prevent access to things the browser/user doesn't need access to -- for example, a database connection script -- but you need access to this file. Prevent spam bots with a with the use of a captcha.
×
×
  • 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.