Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Posts posted by GingerRobot

  1. LOL

     

    It's a tie. Internet Explorer 8 passes more of the World Wide Web Consortium's CSS 2.1 test cases than any other browser, but Firefox 3 has more support for some evolving standards

     

    Really?

  2. You're saying that's better? It's still creating a copy. There are times where I would like the original array.

     

    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.

  3. if an1 else reads this post i wanna solve this with help i dont want it done completly im trying to learn this stuff but if i gotta post in freelance please tell me how i find it

     

    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?

  4. I never like sort being a permutable function.

    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.

  5. 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.

  6. 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.

  7. 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.

  8. Further, psychologists believe that small children lack the skill of self-perception, and it's also widely believed that other animals entirely lack that skill as well, even as adults.

     

    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.

  9. 1: Is it possible to define a variable that will give me a total number of results in the foreach statement?

     

    You mean, like start a counter and increment it each time it runs?

     

    $counter = 0;
    foreach ($rss->items as $item)
    {
    $counter++;
    }
    

     

    2: Is it possible to archive a page numbering system with foreach?

     

    Sorry?

  10. 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.

  11. 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.

  12. 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.

     

     

  13. but I feel like Twitter is just a website dedicated to the same thing that Facebook statuses accomplish

     

    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?

  14. 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>
    

×
×
  • 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.