Jump to content

galvin

Members
  • Posts

    614
  • Joined

  • Last visited

Posts posted by galvin

  1. Yes, we did discuss that option before, but as I said then, it's not feasible to do it in the query (in this case) because there isn't one single query bringing back the data that ends up in the array I'm trying to sort.  The array is built in multiple steps from multiple queries so the sorting needs to be done after it's fully built.

     

     

  2. I have an array called "fullrosterafter" and it contains the info you see at the very bottom of this post.

     

    The first index is positionid (1 thru 4 where 1 is QB, 2 is RB, 3 is WR and 4 is TE).  Then the subarrays (which holds all the info) have an index of playerid.

     

    I simply want to sort this entire array by "positionid" first and then by "ranking" (It's basically in order by positionid already, but assume it's not). 

     

    When I run the code below (it's one of about 15 attempts I've made and it's wrong, but figured I'd have to show you something :), it's not sorting by "ranking" properly.  What am I doing wrong?

     

    foreach ($fullrosterafter as $ID => $row) {
    	$positionid[$ID] = $row['positionid'];
    	$ranking[$ID]= $row['ranking'];
    }
    	array_multisort($positionid, SORT_ASC, $ranking, SORT_ASC, $fullrosterafter);

     

     

    Array
    (
        [1] => Array
            (
                [2] => Array
                    (
                        [playerid] => 2
                        [ranking] => 3
                        [positionid] => 1
                        [lastname] => Brees
                        [firstname] => Drew
                        [teamid] => 10
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => qb
                        [nickname] => Saints
                        [location] => New Orleans
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                        [involved] => involved
                    )
    
                [37] => Array
                    (
                        [playerid] => 37
                        [ranking] => 18
                        [positionid] => 1
                        [lastname] => Freeman
                        [firstname] => Josh
                        [teamid] => 9
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => qb
                        [nickname] => Buccaneers
                        [location] => Tampa Bay
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                        [involved] => involved
                    )
    
                [450] => Array
                    (
                        [playerid] => 450
                        [ranking] => 26
                        [positionid] => 1
                        [lastname] => Wilson
                        [firstname] => Russell
                        [teamid] => 13
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => qb
                        [nickname] => Seahawks
                        [location] => Seattle
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                        [involved] => involved
                    )
    
            )
    
        [2] => Array
            (
                [74] => Array
                    (
                        [playerid] => 74
                        [ranking] => 4
                        [positionid] => 2
                        [lastname] => Johnson 
                        [firstname] => Chris 
                        [teamid] => 26
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => rb
                        [nickname] => Titans
                        [location] => Tennessee
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                    )
    
                [108] => Array
                    (
                        [playerid] => 108
                        [ranking] => 1
                        [positionid] => 2
                        [lastname] => Foster
                        [firstname] => Arian
                        [teamid] => 25
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => rb
                        [nickname] => Texans
                        [location] => Houston
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                        [involved] => involved
                    )
    
                [80] => Array
                    (
                        [playerid] => 80
                        [ranking] => 24
                        [positionid] => 2
                        [lastname] => McGahee 
                        [firstname] => Willis 
                        [teamid] => 29
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => rb
                        [nickname] => Broncos
                        [location] => Denver
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                        [involved] => involved
                    )
    
            )
    
        [3] => Array
            (
                [258] => Array
                    (
                        [playerid] => 258
                        [ranking] => 2
                        [positionid] => 3
                        [lastname] => Jones
                        [firstname] => Julio
                        [teamid] => 12
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => wr
                        [nickname] => Falcons
                        [location] => Atlanta
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                    )
    
                [211] => Array
                    (
                        [playerid] => 211
                        [ranking] => 5
                        [positionid] => 3
                        [lastname] => Nicks
                        [firstname] => Hakeem
                        [teamid] => 3
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => wr
                        [nickname] => Giants
                        [location] => New York
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                    )
    
                [267] => Array
                    (
                        [playerid] => 267
                        [ranking] => 33
                        [positionid] => 3
                        [lastname] => Moore
                        [firstname] => Denarius
                        [teamid] => 31
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => wr
                        [nickname] => Raiders
                        [location] => Oakland
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                    )
    
                [417] => Array
                    (
                        [playerid] => 417
                        [ranking] => 125
                        [positionid] => 3
                        [lastname] => Toon
                        [firstname] => Nick
                        [teamid] => 10
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => wr
                        [nickname] => Saints
                        [location] => New Orleans
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                        [involved] => involved
                    )
    
            )
    
        [4] => Array
            (
                [298] => Array
                    (
                        [playerid] => 298
                        [ranking] => 6
                        [positionid] => 4
                        [lastname] => Finley
                        [firstname] => Jermichael
                        [teamid] => 7
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => te
                        [nickname] => Packers
                        [location] => Green Bay
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                    )
    
                [311] => Array
                    (
                        [playerid] => 311
                        [ranking] => 16
                        [positionid] => 4
                        [lastname] => Cook
                        [firstname] => Jared
                        [teamid] => 26
                        [feet] => 0
                        [inches] => 0
                        [weight] => 0
                        [born] => 0000-00-00
                        [college] => 
                        [display] => YES
                        [ppradjustment] => 0
                        [injured] => no
                        [sportid] => 1
                        [position] => te
                        [nickname] => Titans
                        [location] => Tennessee
                        [qb_matchup] => 
                        [rb_matchup] => 
                        [wr_matchup] => 
                        [te_matchup] => 
                    )
    
            )
    
    )

  3. Nope just had another variable called "$before" in between creating the array and outputting it that was screwing things up (very sorry about that).  So yes, I now get what you get.  And while I assume there are always exceptions, in general, you're saying I should be able to use this single array to get any of the "Player" table info I want by using either their position or player id (without having to create new arrays for each position), correct?

     

    Thanks again, your answers are always so helpful/insightful.

     

     

     

  4. I figured there was an easier way. Let's say I'm originally querying my database with this...

     

    $sql = "SELECT * from players";
    		$startrosterbefore = mysql_query($sql, $connection);
    		if (!$startrosterbefore) {
    		die("Database query failed: " . mysql_error());
    		} else {
    			$before=array();
    			while ($row = mysql_fetch_assoc($startrosterbefore)) {
                                $before[$row['positionid']][$row['playerid']] = $row;
    }
    
    
    
    

    Is that what you mean?  If I do that, I get an empty array so I'm obviously missing something in terms of building the original array.

     

    I think I get it that once I build the original array, I'll be able to access info about different positions easily because of the indexes.  I just am not building it properly I guess.

  5. Your debugging code produces this below (i.e. 2 running backs) so I can't figure out why my code ends up displaying $startingRBsbefore with only ONE RB (i..e. Murray).    Johnson is getting overwritten somehow.

     

    Array
    (
        [positionid] => 2
        [ranking] => 4
        [position] => rb
        [teamid] => 26
        [nickname] => Titans
        [location] => Tennessee
        [firstname] => Chris 
        [lastname] => Johnson 
    )
    Array
    (
        [positionid] => 2
        [ranking] => 7
        [position] => rb
        [teamid] => 2
        [nickname] => Cowboys
        [location] => Dallas
        [firstname] => DeMarco
        [lastname] => Murray
    )

     

    in fact, even when I use your more efficient code instead of mine, I get the same result.  In other words, this code....

     

    if ($row['positionid'] =="2")
        {
            echo "<pre>" . print_r($row, 1) . "</pre>";
        }    
    if ($row['positionid'] =="2")
        {
            $startingRBsbefore[$row['playerid']] = $row;
        }

     

    Produces this result when $startingRBsbefore is outputted using print_r...

     

    Array ( [] => Array ( [positionid] => 2 [ranking] => 7 [position] => rb [teamid] => 2 [nickname] => Cowboys [location] => Dallas [firstname] => DeMarco [lastname] => Murray ) )
  6. I'm perplexed by this, but I'm sure it's something obvious to a smarter person.  I have an array called $startersrosterbefore that has lost of football players in it (with info like ranking, position, team, firstname, etc). There are definitely TWO running backs in this array (i.e. two players with a "positionid" equal to "2"). 

     

    When I run the code below, to grab any Running backs and put them in their own array, it is only keeping the LAST running back it finds, not all of them.

     

    Can anyone tell what's wrong?

     

    	
    $startingRBsbefore=array();
    
    foreach ($startersrosterbefore as $ID => $row) {
    	   if ($row['positionid'] =="2") {
    		$startingRBsbefore[$row['playerid']][ranking]=$row['ranking'];
    	  	$startingRBsbefore[$row['playerid']][positionid]=$row['positionid'];
    		$startingRBsbefore[$row['playerid']][position]=$row['position'];
    		$startingRBsbefore[$row['playerid']][teamid]=$row['teamid'];
    		$startingRBsbefore[$row['playerid']][nickname]=$row['nickname'];
    		$startingRBsbefore[$row['playerid']][location]=$row['location'];
    		$startingRBsbefore[$row['playerid']][firstname]=$row['firstname'];
    		$startingRBsbefore[$row['playerid']][lastname]=$row['lastname'];
    	  }

  7. You should be using a single joined query to get all the related data you want in the order that you want it with one query.

    I really don't think I can with the nature of my data, but I will brainstorm some more to make sure.  In very general plain english, I start with a roster, then some stuff happens, a mysql query is done to get info about new players and the changes are made to the full roster array (removing and adding players). Then some more stuff is done, another separate mysql query is done and more changes are made to the full roster array and then I end up with my new, changed full roster array.

     

    Even if I sort both queries by position, ranking, the ultimate array will still not be in that perfect order.  After the first query it will be in perfect order, but if the second query ends with another QB being added to the array, then he gets added to the end of the array ( after other RBs, WRs, TEs, etc). 

     

    If you output a html <pre> tag before you use print_r on your array, the output will be formated so that it is readable.

    How I'm just learning about this is maddening  >:(  Thank you SO much!  Very helpful.

     

    If you reread the multisort examples, you will see that the array_multisort statement is after the foreach(){} loop that is extracting the values to sort on.

    Ugh, stupid, stupid, stupid. Thank you for pointing that out.

  8. I wish I could sort it in the query, but I'm building the array from multiple queries, so it's not feasible. 

     

    So I'm trying to use array_multisort, per maxudaskin's suggestion.  But when I do this below, it gives an error of "Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent in..."

     

     

    foreach ($fullrosterafter as $ID => $info) {
    	// Obtain a list of columns
    	$positionid[$ID] = $info['positionid'];
    	$ranking[$ID] = $info['ranking'];
    
    	array_multisort($positionid, SORT_ASC, $ranking, SORT_ASC, $fullrosterafter);
    	print_r($array);
    }

     

    FYI, the array is created with these elements...

     

    	                        $fullrosterafter[$row['playerid']][ranking]=$row['ranking'];
    				$fullrosterafter[$row['playerid']][positionid]=$row['positionid'];
    				$fullrosterafter[$row['playerid']][position]=$row['position'];
    				$fullrosterafter[$row['playerid']][teamid]=$row['teamid'];
    				$fullrosterafter[$row['playerid']][nickname]=$row['nickname'];
    				$fullrosterafter[$row['playerid']][location]=$row['location'];
    				$fullrosterafter[$row['playerid']][firstname]=$row['firstname'];
    				$fullrosterafter[$row['playerid']][lastname]=$row['lastname'];

     

    and the final array (which I later try to loop through with the array_multisort code above) looks like this...

     

    Array ( [133] => Array ( [positionid] => 2 [ranking] => 15 [position] => rb [teamid] => 2 [nickname] => Cowboys [location] => Dallas [firstname] => DeMarco [lastname] => Murray ) [208] => Array ( [positionid] => 3 [ranking] => 18 [position] => wr [teamid] => 6 [nickname] => Vikings [location] => Minnesota [firstname] => Percy [lastname] => Harvin ) [298] => Array ( [positionid] => 4 [ranking] => 4 [position] => te [teamid] => 7 [nickname] => Packers [location] => Green Bay [firstname] => Jermichael [lastname] => Finley ) [88] => Array ( [positionid] => 2 [ranking] => 9 [position] => rb [teamid] => 10 [nickname] => Saints [location] => New Orleans [firstname] => Darren [lastname] => Sproles ) [311] => Array ( [positionid] => 4 [ranking] => 15 [position] => te [teamid] => 26 [nickname] => Titans [location] => Tennessee [firstname] => Jared [lastname] => Cook ) [1] => Array ( [ranking] => 3 [positionid] => 1 [position] => qb [teamid] => 20 [nickname] => Patriots [location] => New England [firstname] => Tom [lastname] => Brady ) [7] => Array ( [ranking] => 24 [positionid] => 1 [position] => qb [teamid] => 19 [nickname] => Bills [location] => Buffalo [firstname] => Ryan [lastname] => Fitzpatrick ) [4] => Array ( [ranking] => 26 [positionid] => 1 [position] => qb [teamid] => 30 [nickname] => Chiefs [location] => Kansas City [firstname] => Matt [lastname] => Cassel ) [59] => Array ( [ranking] => 21 [positionid] => 2 [position] => rb [teamid] => 18 [nickname] => Dolphins [location] => Miami [firstname] => Reggie [lastname] => Bush ) [104] => Array ( [ranking] => 28 [positionid] => 2 [position] => rb [teamid] => 28 [nickname] => Colts [location] => Indianapolis [firstname] => Donald [lastname] => Brown ) [464] => Array ( [ranking] => 104 [positionid] => 2 [position] => rb [teamid] => 29 [nickname] => Broncos [location] => Denver [firstname] => Lance [lastname] => Ball ) [175] => Array ( [ranking] => 1 [positionid] => 3 [position] => wr [teamid] => 5 [nickname] => Lions [location] => Detroit [firstname] => Calvin [lastname] => Johnson ) [384] => Array ( [ranking] => 46 [positionid] => 3 [position] => wr [teamid] => 27 [nickname] => Jaguars [location] => Jacksonville [firstname] => Justin [lastname] => Blackmon ) [243] => Array ( [ranking] => 67 [positionid] => 3 [position] => wr [teamid] => 4 [nickname] => Redskins [location] => Washington [firstname] => Anthony [lastname] => Armstrong ) [279] => Array ( [ranking] => 13 [positionid] => 4 [position] => te [teamid] => 32 [nickname] => Chargers [location] => San Diego [firstname] => Antonio [lastname] => Gates ) )

     

    1.  Any idea why I'm getting this inconsistent error?

     

    2.  I googled and someone said you need commas in the array.  But I added commas, but it didn't help.  However, I'm still curious if I should be using commas.  So a side question:  Should I get in the habit of putting commas in my arrays?

  9. I swear I have just been reading through ksort and asort on php.net for 45 minutes and I can't figure out what I need to do.  I have an array that had data entered in this format...

     

    $fullrosterafter[$row['playerid']][ranking]=$row['ranking'];
    $fullrosterafter[$row['playerid']][positionid]=$row['positionid'];
    $fullrosterafter[$row['playerid']][position]=$row['position'];
    $fullrosterafter[$row['playerid']][teamid]=$row['teamid'];
    $fullrosterafter[$row['playerid']][nickname]=$row['nickname'];
    $fullrosterafter[$row['playerid']][location]=$row['location'];
    $fullrosterafter[$row['playerid']][firstname]=$row['firstname'];
    $fullrosterafter[$row['playerid']][lastname]=$row['lastname'];
    

     

    So once it had data, an example of how the print_r would look is...

    Array ( [18] => Array ( [positionid] => 1 [ranking] => 7 [position] => qb [teamid] => 29 [nickname] => Broncos [location] => Denver [firstname] => Peyton [lastname] => Manning ) [74] => Array ( [positionid] => 2 [ranking] => 6 [position] => rb [teamid] => 26 [nickname] => Titans [location] => Tennessee [firstname] => Chris [lastname] => Johnson ) [133] => Array ( [positionid] => 2 [ranking] => 15 [position] => rb [teamid] => 2 [nickname] => Cowboys [location] => Dallas [firstname] => DeMarco [lastname] => Murray ) [208] => Array ( [positionid] => 3 [ranking] => 18 [position] => wr [teamid] => 6 [nickname] => Vikings [location] => Minnesota [firstname] => Percy [lastname] => Harvin ) [258] => Array ( [positionid] => 3 [ranking] => 2 [position] => wr [teamid] => 12 [nickname] => Falcons [location] => Atlanta [firstname] => Julio [lastname] => Jones ) [211] => Array ( [positionid] => 3 [ranking] => 14 [position] => wr [teamid] => 3 [nickname] => Giants [location] => New York [firstname] => Hakeem [lastname] => Nicks ) [298] => Array ( [positionid] => 4 [ranking] => 4 [position] => te [teamid] => 7 [nickname] => Packers [location] => Green Bay [firstname] => Jermichael [lastname] => Finley ) [6] => Array ( [positionid] => 1 [ranking] => 16 [position] => qb [teamid] => 8 [nickname] => Bears [location] => Chicago [firstname] => Jay [lastname] => Cutler ) [88] => Array ( [positionid] => 2 [ranking] => 9 [position] => rb [teamid] => 10 [nickname] => Saints [location] => New Orleans [firstname] => Darren [lastname] => Sproles ) [267] => Array ( [positionid] => 3 [ranking] => 26 [position] => wr [teamid] => 31 [nickname] => Raiders [location] => Oakland [firstname] => Denarius [lastname] => Moore ) [311] => Array ( [positionid] => 4 [ranking] => 15 [position] => te [teamid] => 26 [nickname] => Titans [location] => Tennessee [firstname] => Jared [lastname] => Cook ) ) 
    

     

    All I want to do is cycle through this array and sort the output by "positionid" first (1, then 2, then 3, up through 6) and within each group of positions, I want to sort by "ranking".

     

    So QBs (positionid of 1) would come first.  And Peyton Manning would be the very first player outputted since his ranking is 7.  Jay Cutler would be next with a ranking of 16.  Then it would move on to the RBs (positionid of 2). And so on.

     

    I tried all sorts of things in the ksort function, but nothing seems to change the order of my output.

     

    ksort(?????);  //cannot figure out what to put here, which makes me think maybe I shouldn't be using ksort at all
    foreach ($fullrosterafter as $ID => $info) {
    		$output .="<div class='$class'>" . strtoupper($info['position']) . " - " . $info['firstname'] . " " . $info['lastname'] . ", " . $info['nickname'] . " (" . $info['ranking'] . ")</div>";
    }

  10. This may not make sense and I apologize in advance if it doesn't :) 

     

    Anyway, say I have an array with data like this ...

     

    $myarray[1]=red;

    $myarray[1][animal]=tiger;

    $myarray[1][state]=washington;

    $myarray[1][food]=pizza;

    $myarray[2]=blue;

    $myarray[2][animal]=lion;

    $myarray[2][state]=california;

    $myarray[2][food]=spaghetti;

    $myarray[3]=green;

    $myarray[3][animal]=cat;

    $myarray[3][state]=new york;

    $myarray[3][food]=hamburger;

     

    How can I do a foreach loop and have all that info available to print out to the browser?  NOTE:  If there is something other than a foreach loop that makes more sense to use in this situation, I'm all ears :)

     

    For example, if I want output like...

     

    Player 1 -- color: red, animal: tiger, state: washington, food: pizza

    Player 2 -- color: blue, animal: lion, state: california, food: spaghetti

    Player 3 -- color: green, animal: cat, state: new york, food: hamburger

     

    This is what I'm trying to do, but clearly getting nowhere...

    	
    foreach ( $myarray as ????????) { //and this is where I get lost.  I know how to do it if there is just one index and one value, but I'm getting confused with the two index setup and multiple "types" of values
    echo *proper code that will spit out output above*;
    }

     

  11. Do not use SELECT * especially in multi-table queries.

     

    Are you at all flexible on that?  For example, say you are querying a table that has 20 columns and you need to use 17 of them?  Would you use "SELECT *" in that case, or would you stick to your guns and actually list out the specific 17 fields you need (i.e. SELECT column1, column2, ... column17)?

     

    Just curious, as I'm trying to adopt good/proper habits :)

     

     

  12. Say I have four simple tables likes this, based on the National Football League...

     

    table (fields)

    players (playerid, firstname, lastname, teamid, positionid)

    positions (positionid, position)

    teams (teamid, teamname)

    schedule (gameid, homeid, awayid, weeknum, seasonnum)  NOTE:  Every team has 16 games listed in the schedule table (8 home and 8 away, plus they will also have a BYE week, for 17 total)

     

    I want to query my database and get the following info from those tables and display it like this...

     

    NOTE: It would repeat the following for EVERY player that I query on (more on the specific query below)

     

    firstname lastname - teamname (teamid):

    Week 1: v -if home- @ -if away- (opponent's teamname)

    Week 2: v -if home- @ -if away- (opponent's teamname)

    Week 3: v -if home- @ -if away- (opponent's teamname)

    Week 4: v -if home- @ -if away- (opponent's teamname)

    Week 5: v -if home- @ -if away- (opponent's teamname)

    Week 6: v -if home- @ -if away- (opponent's teamname)

    Week 7: v -if home- @ -if away- (opponent's teamname)

    Week 8: v -if home- @ -if away- (opponent's teamname)

    Week 9: v -if home- @ -if away- (opponent's teamname)

    Week 10: v -if home- @ -if away- (opponent's teamname)

    Week 11: v -if home- @ -if away- (opponent's teamname)

    Week 12: v -if home- @ -if away- (opponent's teamname)

    Week 13: v -if home- @ -if away- (opponent's teamname)

    Week 14: v -if home- @ -if away- (opponent's teamname)

    Week 15: v -if home- @ -if away- (opponent's teamname)

    Week 16: v -if home- @ -if away- (opponent's teamname)

    Week 17: v -if home- @ -if away- (opponent's teamname)

     

    For example...

     

    Julio Jones - Falcons (id#):

    Week 1: @ Giants

    Week 2: @ Seahawks

    Week 3: v Redskins

    Week 4: @Patriots

    Week 5: v Bears

    Week 6: v Buccs

    Week 7: @49ers

    Week 8: @Saints

    Week 9:  v Buccs

    Week 10: BYE

    Week 11: @ Eagles

    Week 12: v Cowboys

    Week 13: v Lions

    Week 14: @ Packers

    Week 15: v Rams

    Week 16: v 49ers

    Week 17:  @ Chiefs

     

    This was my apparently really poor attempt at the query because it brings back results that repeat  the same name A LOT...

     

    (side note:  Is it bad practice to try to get this much info in ONE query (i.e. should I do multiple queries)?  Clearly I stink at the whole "join" thing...)

     

    $sql = "SELECT * from players, positions, teams, schedule
    		WHERE players.positionid = positions.positionid
    		AND teams.teamid = players.teamid
    		AND playerid IN ($specificplayerids) //this will be a comma separated string of specific IDs (for example... "47, 57, 103, 8, 17, 19)
    		AND players.teamid = schedule.homeid //this one of many areas where I'm confused. I THINK i need to say, in plain english, =schedule.homeid OR schedule.awayid but not sure 
    		ORDER BY lastname";
    $players= mysql_query($sql, $connection);
    		if (!$players) {
    		die("Database query failed: " . mysql_error());
    		} else {
    			while ($row = mysql_fetch_assoc($players)) {
    				$output .=	"<div>" . $row['firstname'] . " " . $row['lastname'] . ", " . $row['teamname'] . " </div>";
    			}  //I tried to just get it to list names first (i.e. I didn't even try to get the schedule part), but I can't even get just the names to display right.  :-\
    		}

  13. Thank you PFMaBiSmAd for asking this question... "where you are displaying it after retrieving it from the database table?".  That was the problem.  The full data WAS in the database, but that displaying page was using single quotes in the value attribute so it cut it off when displaying. 

     

    Ugh, I hate the double quote/single quote dilemma (at least it's a dilemma for me :) )

     

    Do you suggest any general theories, like maybe "Always use double quotes even though it's annoying to have to escape them"?

     

  14. Sorry, here is the code for the form.  now that I see it, I'm assuming the fact that I am using single quotes for the value attribute in the form is probably not good (i.e. I should use double quotes??). I'll try that now...

     

    Form:

    <form id="addplayer" method="post" action="insertnewplayer.php">
    
    First Name: <input type='input' name='firstname' size='25' value='' /><br />
    Last Name: <input type='input' name='lastname' size='50' value='' /><br />
    
    <input type='submit' name='submit'  value='Submit' /><br /></form>

     

     

  15. I have insert code like this...

    $sql="INSERT into players (lastname, firstname) VALUES ('" . mysql_prep($_POST['lastname']) . "', '" . mysql_prep($_POST['firstname']) . "')"; 

     

    If I have first name like "Da'Rel", the insert goes through, but it only puts "Da" in the firstname field. 

     

    Here is my mysql_prep code...

     

    	function mysql_prep($value) {
    	$magic_quotes_active = get_magic_quotes_gpc();
    	$new_enough_php = function_exists("mysql_real_escape_string") ; //i.e. PHP >= v4.3.0
    	if($new_enough_php) { //PHP v4.3.0 or higher
    		//undo any magic quote effects so mysql_real_escape_string can do the work
    		if($magic_quotes_active) { $value = stripslashes($value) ;}
    		$value = mysql_real_escape_string($value);
    	} else { //before php v4.3.0
    		// if magic quotes aren;t already on then add slashes manually
    		if(!magic_quotes_active) { $value = addslashes($value); }
    		// if magic quotes are active, then the slashes already exist
    	}
    	return $value;
    }
    

     

    Any idea what I need to alter in order to let single quotes go into the field (i.e. so that the full name "Da'Rel" gets inserted")?

     

  16. Follow up...  Using my same example, is there a way using JQuery to trigger an event when any one of my checkboxes is checked? 

     

    I found this code below online, but this is checking one specific checkbox.  I might have  A LOT of checkboxes, so I'd rather not have to have a click function for every one of my individual checkboxes,  looking to see if one is checked...

     

    $('#myCheckBox').click (function ()
    {
    var thisCheck = $(this);
    if (thischeck.is (':checked'))
    {
    // Do stuff
    }
    });

     

    I feel like I should be able to use a similar version of .josh's reply earlier, i.e something like....

     

      if ($(this).find('input[name="checkedboxes[]"]:checked').length == 1) {
          alert('someone checked a box!');
         }

     

    But I can't figure out how I would run that code WHEN someone checks any one of my potentially many checkboxes.  Any ideas?

  17. I have a form with several checkbox inputs that submits to a PHP page via Post and the selected checkboxes are posted to an array (each input has a name of "checkedboxes[]" so that an array is created in $_POST['checkedboxes']);

     

    However, before it submits, I want to use javascript to make sure the user checked at least one checked. I know how to check it using PHP, but again, I want to do it without leaving the page, so I want to use javascript.

     

    Can anyone help?    I've googled and it seems I will have to use something like onclick='return validate();' or maybe onsubmit='return validate();' but I am having trouble obviously, figuring out how to actually check in the validate function (if that is in fact the right way to do it).

     

    Here's the example code.  Again, just want to make sure the user checks at least ONE of those 4 boxes...

     

    <form id="form" method="post" action="nextstep.php">
    <input type="checkbox" name="checkedboxes[]" value="1">
    <input type="checkbox" name="checkedboxes[]" value="2">
    <input type="checkbox" name="checkedboxes[]" value="3">
    <input type="checkbox" name="checkedboxes[]" value="4">
    <input type='submit' name='submit' value='Submit' />
    </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.