Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Posts posted by GingerRobot

  1. You're not assigning the return value of the array_map function to anything. If you take a look at the manual page (array_map) you'll see the function returns the array after having applied the supplied function to all the elements of the array.

     

    This is something you have to keep an eye on with the array function; some do their job in-place, others create a copy.

  2. Can I do it somehow that this

    while(list($PlayerIDnumb, $PointsScored) = mysql_fetch_row($result)){
         $PS_sum=$PS_sum+$PointsScored;
    }
    

    remains the same?

     

    I don't really want to change it as it's actually as an include and also used elsewhere.

     

    Surely it doesn't matter if the end result is the same? All I was saying is that running a query in a loop is a pretty inefficient way of doing things and requires you to write much more code than is necessary.

  3. Ouch...you really don't need to to loop through the results and execute a query for each player. You can use a join. I think this should work for you:

     

    SELECT table1.PlayerName, SUM(table2.PointsScored),table2.SeasonNum FROM table1,table2 WHERE table1.PlayerID=table2.PlayerIDnumb GROUP BY(table1.PointsScored) ORDER BY table1.PlayerName, table2.SeasonNum
    

     

    If you then loop through those results, you should get what you need:

     

    $sql = "SELECT table1.PlayerName, SUM(table2.PointsScored),table2.SeasonNum FROM table1,table2 WHERE table1.PlayerID=table2.PlayerIDnumb GROUP BY(table1.PointsScored) ORDER BY table1.PlayerName, table2.SeasonNum";
    $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
    
    while(list($name,$score,$season) = mysql_fetch_row($result)){
        echo "$name, $score, $season <br>";
    }
    

     

    Edit: You can find a tutorial on joins here: http://www.phpfreaks.com/tutorial/data-joins-unions

  4. Firstly, the board you posted is is not a help forum. I would have thought that having that written in bold and capitals would be enough for you to see that, but apparently not.

     

    As cags says, if you're looking for something in a file you could just use the find option in almost any editor. If you wish to search through lots of files at once and are using a *nix operating system, you could use grep...

     

    For example, the following would look through all files with a .php extension in the current folder and print out any lines with an asterisk is them.

     

    grep -H -n \* *.php
    

     

     

  5. Well there's nothing syntactically wrong with your if statement, so i suggest you find out what is stored in $sub_attribute_name_attribute (incidentally, i'm all for descriptive variable names -- but sheesh). You can then go about finding out why it doesn't contain the value you thought it should. Echo out the variable prior to the if statement.

     

    Or, to put it another way, i'm sleepy and didn't notice the missing quotes.

  6. You'll need to use regular expressions (e.g. preg_replace) to replace the tags with <b> and </b> tags respectively. The same applies for other tags. I'm sure if you google, you'll find tutorials/examples/code snippets of this kind of thing anyway.

     

    You should replace the bbcode for HTML tags when you display data, not before you insert it into the database.

  7. Well for starters, what operating system are you using? Also, what program are you using to view the results? If you use a web browser to look at the file, you might well get everything all on one line if it treats it as HTML rather than a text file (i'm unsure if browsers will be doing this -- i'd expect most would assume it's a text file, but it's a possibility)

  8. I was wondering how I can get the ID of an item I just inserted into the database, without using another query to fetch the last item in the database

     

    Just FYI, it would be a bad idea to use a second query to select the last inserted ID; there's no guarantee that it is the same as the one you've just inserted because of concurrency issues. For example, if two users (A and B) are loading the page at the same time, it could be that B's insert would happen inbetween A's insert and A's select, resulting in user A receiving the ID that was inserted by user B.

     

    The LAST_INSERT_ID() function works on a per-connection basis. It is therefore safe from this kind of thing.

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