Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Well...the obvious question is: do you create regular backups?
  2. If you just want to get the last 4 characters, use substr
  3. Yes, i am saying that's better. As you say, there are times when you want the original. But there are times you don't. Sure, it pushes the problem back to the programmer but it still gives the best solution.
  4. Well what have you tried so far? I dont even know what you're trying to do. All i know is you're trying to create two files: insert.php and results.php. Now i'm going to take a guess that you're supposed to be inserting something into a database on the one page and displaying them in the other. Have you tried any basic PHP tutorials? Why don't you try learning some PHP first?
  5. I'll agree it would be much nicer being able to say $sortedArray = sort(array(3,1,4,1,5,9)); If that's what Ken actually meant (or was he trying to be funny?), then that wouldn't be better IMO. Without looking under the hood, i'm guessing PHP uses quicksort(and indeed it does) and one of the reasons for that will be it's relatively low memory requirements. By creating a copy, that benefit will be removed.
  6. If you want someone to do this for you, you need to be posting in the freelance section.
  7. By 'nothing happens', do you mean you get a blank screen? If so, i expect there are errors and you need to display them. You can do this by adding these two lines to the top of your script: error_reporting(E_ALL); ini_set('display_errors','On'); Otherwise, we're going to need to see your actual code.
  8. I'm not sure i really follow exactly what you're trying to do, but it sounds like a bad idea. The referrer is sent by the user (well, their browser anyway) and, as such, can't be trusted. It could easily be spoofed, so using for some part of your game is a no-no really. Not only that, but browsers can be set up not to send the referrer and some firewalls block it -- so you could end up causing problems for legitimate users.
  9. Well, i suspect it's going to be more in place of your existing code rather than added to it. You already have code that selects information and displays it, so you're going to have to put the two pieces together. I've commented roughly what should happen where, so it shouldn't be too difficult.
  10. In fact, apes are one of the very few animals for which there is actually any evidence of self-awareness. Of course, it's pretty difficult to determine whether or not something is self-aware.
  11. You mean, like start a counter and increment it each time it runs? $counter = 0; foreach ($rss->items as $item) { $counter++; } Sorry?
  12. Further, you need to consider the weak vs strong AI debate. For example, some people claim that simply performing some given algorithm constitutes artificial intelligence, whilst others state that it is, in some sense, necessary to understand what it is you are doing and be self-aware. See John Searle's Chinese Room argument for more on this.
  13. Well, you would construct links such as www.yoursite.com/yourpage.php?orderby=somefield&dir=ASC. If you want to allow for orderings on multiple fields, it'll get more complicated but a simple setup would be something like: <?php $fields = array('field1','field2','field3','field4','field5'); if(!isset($_GET['orderby'] || !in_array($_GET['orderby'],$fields) ){ //if the user's not clicked a link or if the field isn't one we're sorting by(also prevents SQL injection) //set a default field $orderby = 'defaultField'; }else{ //otherwise, we set the order by to the field in the URL $orderby = $_GET['orderby']; } if(!isset($_GET['dir']) || ($_GET['dir'] != 'ASC' && $_GET['dir'] != 'DESC')){ //same thing for direction $dir = ASC }else{ $dir = $_GET['dir']; } //show headings. Assuming a table: echo '<table><tr>'; foreach($fields as $field){ if(isset($_GET['orderby'] && $_GET['orderby'] == $field){ //if we're already ordering by this field, we swap the the direction of the order if($dir == 'ASC'){ $newdir = 'DESC'; }else{ $newdir = 'ASC'; } }else{ //otherwise, we set the default ordering $newdir = 'ASC'; } echo '<th><a href="' . $_SERVER['PHP_SELF'] . '?orderby= ' . $field . '&dir='. $newdir .' ">'. $field .'</a></th>'; } $sql = "SELECT * FROM yourtable ORDER BY $orderby $dir"; //execute the query //display results Note that we save ourselves a lot of work by placing the fields in an array and looping through. This also allows us to check the user is passing us a valid field by using the array as a whitelist too.
  14. Firstly, do you know about ordering the results with an SQL query? You can just use ORDER BY field DIRECTION e.g: SELECT * FROM yourtable ORDER BY somefield ASC SELECT * FROM yourtable ORDER BY somefield DESC Of course, you may wish to sort by one field, then another: SELECT * FROM yourtable ORDER BY somefield ASC, otherfield DEC Now, all you need to do is make each of your headings a link to the same page and pass some parameters in the URL to contain which field you're ordering by and the direction.
  15. Not just me then. As far as i can tell Twitter is facebook/myspace status updates without the rest of the social networking stuff. What the hell is the point?
  16. It's for this very reason that it's often easier to have forms submit to themselves. You can do the processing at the top and, if there's errors, very easily populate the form. For example: <?php $errors = false; if(count($_POST) > 0 ){ //form has been submitted to process if(players_cost_too_much){ $errors = true; }else{ //show thanyou page or whatever } } <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <?php if($errors){ //print some error text } <input type="text" name="somefield" value="<?php echo (isset($_POST['somefield'] && $errors)) ? $_POST['somefield'] : '';?>" /> </form>
  17. But that doesn't mean the error has just gone away. It just means you're leaving it un-addressed. That's really not a good idea.
  18. 1.) Do you have session_start at the top of your page? 2.) Do you have all errors turned on and display errors on? If you're not sure, add these to the top of your script: ini_set('display_errors','On'); error_reporting(E_ALL);
  19. We're probably going to need to see some code. It might a variable issue -- the included file might have some variables with the same names as those in the file doing the including and thus it's screwing things up. But without any code, i'm just stabbing in the dark really.
  20. My intention is not to attack you but to attempt to make you see that, in this instance, the code you're suggesting isn't that great. I've seen you post it up so many times in various forms and i've also seen other criticisms of it. That leaves me with no choice but to show, in the bold light of day, that it was a bit pointless.
  21. Ok, so it sounds like you know what you want to do. Do you have anything so far? Is there any particular part you're struggling with?
×
×
  • 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.