Jump to content

esiason14

Members
  • Posts

    58
  • Joined

  • Last visited

    Never

Everything posted by esiason14

  1. I'm just trying to match something like this: [code][url=http://mydomain.com/nfl/players/playerpage/1234/rss]Read more...[/url][/code] and replace it with [code]<a href="http://www.mydomain.com/whatever.php">Read more...</a>[/code] any help would be appreciated
  2. What I'm trying to do is read a csv file and insert it into my db. I find all of the ticker symbols from the db...then for each one I want to loop through and insert the values from the csv file where the ticker_symbols are the same. Since the symbol is not included in the file, I add the symbol to the array ( $arr[] = $value;). Anyway, the insert works for only the first symbol and then I get the following error: [CODE]Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\stocks\insert.php on line 25[/CODE] Line 25 is [CODE]while ($ticker = mysql_fetch_array($result))[/CODE] Code [code=php:0]$sql3 = "SELECT ticker_symbol from stocks order by ticker_symbol"; if (!$result = mysql_query($sql3)) { die("Could not get the the ticker symbols: " . mysql_error() . "<br />\n"); } while ($ticker = mysql_fetch_array($result)) { foreach ($ticker as $value)   {     $fcontents = file ('http://www.adomain.com/table.csv?s='.$value.'&a=02&b=13&c=1986&d=06&e=28&f=2008&g=d&ignore=.csv');   for($i=0; $i<sizeof($fcontents); $i++)     {       $line = trim($fcontents[$i]);       $arr = explode(",", $line);       $arr[] = $value;       $sql = "insert into historical_quotes values ('".                   implode("','", $arr) ."')";       mysql_query($sql);       echo $sql ."<br>\n";       if(mysql_error())         {         echo mysql_error() ."<br>\n";         }       }   }[/code] Please enlighten me! :)
  3. I'm trying to pass the player_id as a variable from a drop-down submit form to another page for use in a query. Here is the code for the form: [code]$query = mysql_query("SELECT fname, lname, player_id FROM players ORDER by lname ASC"); ?> <form action=test.php method=POST> <input type="hidden" name="<php echo $player_id ?>" value="<php echo $player_id ?>"> <select name=players> <?php while ($r = mysql_fetch_array($query)) { $fname =  $r["fname"]; $lname = $r["lname"]; $player_id = $r["player_id"]; echo "<option value=$player_id>$fname $lname</option>"; } echo "</select>"; ?> <input type="submit" name="<php echo $player_id ?>" value="Plot Player" /> <input type="reset"> </form>[/code] and the partial code for the output page: [code]$players = $_POST; if (isset($players)) {   $SQL = "SELECT * from playerstats ps, players p WHERE ps.player_id='$players' and p.player_id=ps.player_id and ps.year=2005";   $RESULT = mysql_query($SQL);   if ($myrow=$RESULT) {       do { $labels = $myrow["week"];         //$data2[] =  (($row['pass_yd'] * 0.034) + ($row['pass_td'] * 6) + ($row['twopt'] * 2) + ($row['int'] * -2) + ($row['fmbl_lost'] * -2) + ($row['rush_yd'] * 0.067) + ($row['rush_td'] * 6));         $datawk[] = $myrow["week"];         $data[] = $myrow["pass_yd"];         $data2[] = $myrow["pass_td"]; $lastname = $myrow["lname"]; $firstname = $myrow["fname"];         $data_names[] = $myrow["lname"]."(".$myrow["player_id"].")";       } while ($myrow=$RESULT);   } [/code] Im trying to pass the variable for use in my graphing application. For some reason I can get it to work..See anything that may help me get it working?
  4. [!--quoteo(post=372162:date=May 7 2006, 08:41 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 7 2006, 08:41 PM) [snapback]372162[/snapback][/div][div class=\'quotemain\'][!--quotec--] How so, if you don't mind my asking? [/quote] Sure, no problem. I finally found a source where I can get in-season csv files that I can use to update my stats. A sample record is below (this is for a pitcher with both hitting and pitching stats: [code]"Pedro Martinez",NYM,18,6,14,0,1,0,0,0,1,1,1,5,0,0,.071,.133,.071,.205,6,5,0,0,0,0,0,39.2,22,13,12,6,12,42,2.72,0.86,.163 [/code] Now, maybe I can figure out a way to parse csv and insert the hitting stats into the hitters table and the pitching stats into the pitching table, but I'm not that saavy. Do you think that would be a better solution...if thats even possible?
  5. It probably is very poor table design, but I have several reasons why I want to do this. For the most part, it will make it a lot easier on me to update.
  6. [!--quoteo(post=371833:date=May 6 2006, 12:13 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 6 2006, 12:13 PM) [snapback]371833[/snapback][/div][div class=\'quotemain\'][!--quotec--] Then I don't understand... aren't these stats totally different? [/quote] Yes, they are totally different. I'll try to explain a little better. Some pitchers also rack up hitting stats (those in the National league), so these pitchers currently have stats in the pitcherstats table and hitterstats table. Pitcherstats table looks like this: [code]player_id,year,mlbteam_id,league_id,position_id,games,wins,losses,ip,bfp,ha,hra,bb,ibb,wp,hbp,ko,era,k9,sobb,saves,sho,er,ra,gs,cg,gf,whip,babip[/code] Hitterstats table currently looks like this: [code]player_id ,year,mlbteam_id ,position_id,league_id ,games,ab,runs,hits,doubles,triples,hr,rbi,sb,cs,walks,so,avg,slg,obp,ops     [/code] What I want to do is to combine these tables so that I have one master table...So if a pitcher has no hitting stats, his hitting stats would be 0, but if he does...his hitting and pitching stats would be filled for that particular year record. So the playerstats table would look like this: [code]player_id,year,mlbteam_id,league_id,position_id,games,ab,runs,hits,doubles,triples,hr,rbi,sb,cs,walks,so,avg,slg,obp,ops ,wins,losses,ip,bfp,ha,hra,bb,ibb,wp,hbp,ko,era,k9,sobb,saves,sho,er ,ra,gs,cg,gf,whip,babip[/code] In order to combine these two tables, I have to do a few things: 1) Alter the hitterstats table to include pitcherstats (done) 2) Find the pitchers (by yearly record) who have hitterstats and insert there pitching stats into that recorc 3) Find the pitchers who have no hitterstats (most likely American league pitchers) and create a whole new record in the table.
  7. True, I should have...but I currently have 25+ years of stats and over 45000 stat records. I know the position of each player, thats not the problem...its the combining of the tables thats the problem. Is there a way to do this?
  8. Hi, I currently have two tables: hitterstats and pitcherstats. I would like to combine these into one table called playerstats. Here's my dilemma. Some pitchers (all of whom, obviously, have stats in the pitchers stats table) also have hitting stats in the hitter_stats table, but some dont. So, i need something like this. If the pitchers player_id exists in the hitterstats table for a certain year, then insert the stats into that yearly record. If there is no record for that player_id, then create a new record for that pitchers players_id. im having trouble coming up with this one, so any advice would be appreciated.
  9. Thanks for the help, unfortunately I'm stuck with 4.0.26 :(
  10. I'm trying to get a listing of transactions from this page: [a href=\"http://www.sportsline.com/mlb/transactions\" target=\"_blank\"]http://www.sportsline.com/mlb/transactions[/a] I'm using this, which returns the info all jumbled together (see below) [code]<?php /*** Load the page here ***/ $input = file_get_contents("http://www.sportsline.com/mlb/transactions"); // *** Finding the team transactions between href tags ***/ $trans= preg_match("@<a[\s]+href=/mlb/teams/transactions/(.*)>(.*)</a>@", $input, $matches); // Did we find a match? if ($trans = true) { // Here it is echo '<br />' . strip_tags($matches['1']) . '<br>'; } ?>[/code] Output looks like this: [code]Washington NationalsRecalled OF Ryan Church and INF Brendan Harris from New Orleans of the PCL. Optioned OF Brandon Watson and C Wiki Gonzalez to New Orleans.Wednesday, April 12, 2006Arizona DiamondbacksPlaced LHP Terry Mulholland on the 15-day DL. Purchased the contract of RHP Casey Daigle from Tucson of the PCL.Atlanta BravesRecalled INF Tony Pena from Richmond of the IL.Baltimore OriolesRecalled RHP Chris Britton from Bowie of the Eastern League. Optioned RHP Cory Morris to Ottawa of the IL.Boston Red SoxAgreed to terms with OF Coco Crisp on a three-year contract extension through 2009. Activated LHP David Wells from the 15-day DL. Placed RHP David Riske on the 15-day DL, retroactive to April 5.Milwaukee BrewersClaimed RHP Vince Perkins off waivers from Toronto.Seattle MarinersActivated OF Matt Lawton. Designated C Guillermo Quiroz for assignment. Optioned RHP Jeff Harris to Tacoma of the PCL. Recalled C Rene Rivera from Tacoma.Tampa Bay Devil RaysPlaced 3B Aubrey Huff on the 15-day DL.Texas RangersPlaced 2B Ian Kinsler on the 15-day DL. Activated OF Gary Matthews Jr. from the 15-day DL. Activated INF Marshall McDougall from the 15-day DL and optioned him to Oklahoma of the PCL.Toronto Blue JaysAssigned C Jason Phillips outright to Syracuse of the IL.[/code] I'm trying to get it where I can show each transaction, by team the specified date. Can someone point me in the right direction and/or offer an example/pointers. THanks
  11. Hi Fenway, I've been trying to tweak the query you posted, but haven't been able to get the results I'm looking for. If I use this query [code]SELECT position_id, COUNT( games ) AS cnt FROM temp GROUP BY player_id ORDER BY cnt DESC LIMIT 1;[/code] it returns the position_id 3 with a count of 94. I guess I need a little more help, so I can isolate the count to a specific player for a specific year
  12. I have two tables, one which I am trying to update based on the other. [b] temp table[/b] id year position_id games [b]players[/b] id year position_id Here is the problem...the temp can hold several records per player and even multiple for each year...For example: [b]player_id, year, position_id, games[/b] 4323, 2005, 5, 66 4323, 2005, 4, 20 4323, 2005, 3, 7 This example is for the player_id (4323) for 2005. This player played three different positions (3,4,5). What I want to do , if possible, is to find the position that player played the most games at for that given year and update the players table with that position_id.
  13. I'm trying to update an existing table with csv data. I want to dump it into the table playerstats which is linked to the players table by player_id. So, I need to first find the player_id, that matches the first name and last name of each record in the file before I can import. Make sense? Anyone have any suggestions on how to go about this? It would be much appreciated. Heres a sample record that I want to import: [code]Lance Niekro,SF,9,1,2,0,0,0,2,2,1,0,0,0.222,0.222,0.364,0.586[/code] Here is my playerstats table: [code]CREATE TABLE `playerstats` (   `stat_id` int(10) unsigned NOT NULL auto_increment,   `player_id` smallint(5) unsigned default '0',   `year` smallint(5) unsigned default NULL,   `mlbteam_id` char(3) binary default NULL,   `ab` int(11) default '0',   `runs` int(11) default '0',   `hits` int(11) default '0',   `doubles` int(11) default '0',   `triples` int(11) default '0',   `hr` int(11) default '0',   `rbi` int(11) default '0',   `walks` int(11) default '0',   `so` int(11) default '0',   `sb` int(11) default '0',   `cs` int(11) default '0',   `avg` decimal(4,3) default '0.000',   `slg` decimal(4,3) default '0.000',   `obp` decimal(4,3) default '0.000',   `ops` decimal(4,3) default '0.000',   `wins` int(3) default '0',   `losses` int(3) default '0',   `ip` decimal(4,2) default '0.00',   `ha` int(4) default '0',   `bb` int(4) default '0',   `ko` int(4) default '0',   `era` decimal(3,2) default '0.00',   `k9` decimal(3,2) default '0.00',   `sobb` decimal(3,2) default '0.00',   `saves` int(4) default '0',   `er` int(4) default '0',   `gs` int(4) default '0',   `cg` int(4) default '0',   `whip` decimal(3,2) default '0.00',   PRIMARY KEY  (`stat_id`) ) TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=2962; [/code] PLAYERS Table [code] `player_id` smallint(5) unsigned NOT NULL auto_increment,   `lname` varchar(50) default NULL,   `fname` varchar(50) default NULL,   `picture_loc` varchar(25) default NULL,   `mlbteam_id` char(3) binary default NULL,   `league_abbv` char(2) binary default NULL,   `position_id` char(3) binary default NULL,   `height` varchar(6) NOT NULL default '',   `weight` char(3) NOT NULL default '',   `birth` varchar(10) default NULL,   `college` varchar(50) NOT NULL default '',   `jersey` smallint(2) default NULL,   PRIMARY KEY  (`player_id`) ) TYPE=MyISAM AUTO_INCREMENT=1350;[/code]
  14. Please see the above post. This is how my current output looks when I'm logged in. It shows the check next to the players that I'm currently tracking...but for the ones I'm not, it does not show the submit... [img src=\"http://img155.imageshack.us/img155/363/current9kh.gif\" border=\"0\" alt=\"IPB Image\" /] This is what I have so far (this is only partial): [code]<?php for ($i = $start; $i < $page_limit; $i++) {     // Row color selector     $row_color = ( !($i % 2) ) ? ' bgcolor=#ffffff' : '';     $lname = $stat_list[$i]['lname'];     $fname = $stat_list[$i]['fname'];     $gs = $stat_list[$i]['gs'];     $cg = $stat_list[$i]['cg'];     $wins = $stat_list[$i]['wins'];     $losses = $stat_list[$i]['losses'];     $saves = $stat_list[$i]['saves'];     $player_id = $stat_list[$i]['player_id'];     $mlbteamabbv = $stat_list[$i]['mlbteam_abbv'];     $ip1 = $stat_list[$i]['ip'];         $ip = format_number($ip1, 1);     $ko = $stat_list[$i]['ko'];     $bb = $stat_list[$i]['bb'];     $ha = $stat_list[$i]['ha'];     $sobb = $stat_list[$i]['sobb'];     $k9 = $stat_list[$i]['k9'];     $er = $stat_list[$i]['er'];     $era = $stat_list[$i]['era'];     $whip = $stat_list[$i]['whip'];         $points = $stat_list[$i]['fbr_points'];     $pointsround = ROUND($points, 1); ?> <form name="myplayers" method="post" action="<?php echo $PHP_SELF;?>"> <?php echo "<tr>"; echo "<td$row_color align=\"center\">"; $sessu = mysql_escape_string($_SESSION['username']); $result = mysql_query("SELECT id FROM users WHERE username = '$sessu'"); if (!$result) {    die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_array($result)) {     $id = $row['id']; } $result = mysql_query("SELECT player_id FROM myplayers WHERE user_id = '$id'"); if (!$result) {    die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_array($result)) { $mpid = $row['player_id']; if ($logged_in == 1) {   if ($mpid == $player_id)     { echo "<img src=\"images/ismyp.gif\" border=\"0\"></td>";     }   elseif (!$result)  { echo "<input type=\"image\" src=\"images/addmyp.gif\" value=\"$player_id\" name=\"myplayers\"></td>";         }   }          }     echo "\t\t<td$row_color><a href='/baseball/players.php?player_id=$player_id'>$fname $lname</td>\n";       echo "\t\t<td$row_color>$mlbteamabbv</td>\n";     echo "\t\t<td$row_color$row_color align=\"center\">$pointsround</td>\n";     echo "\t\t<td$row_color align=\"center\">$gs</td>\n";     echo "\t\t<td$row_color align=\"center\">$cg</td>\n";     echo "\t\t<td$row_color align=\"center\">$wins</td>\n";     echo "\t\t<td$row_color align=\"center\">$losses</td>\n";     echo "\t\t<td$row_color align=\"center\">$saves</td>\n";     echo "\t\t<td$row_color align=\"center\">$ip</td>\n";     echo "\t\t<td$row_color align=\"center\">$ko</td>\n";     echo "\t\t<td$row_color align=\"center\">$bb</td>\n";     echo "\t\t<td$row_color align=\"center\">$ha</td>\n";     echo "\t\t<td$row_color align=\"center\">$sobb</td>\n";     echo "\t\t<td$row_color align=\"center\">$k9</td>\n";     echo "\t\t<td$row_color align=\"center\">$er</td>\n";     echo "\t\t<td$row_color align=\"center\">$era</td>\n";     echo "\t\t<td$row_color align=\"center\">$whip</td>\n";     echo "\t</form></tr>\n"; } ?> </table> <?php if(($logged_in == 0) && isset($_POST['myplayers'])) { header("Location: http://www.fantasybaseballresearch.com/login.php");     echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=/login.php">HERE</a> to be redirected</div></body></html>';     exit;   }  elseif (($logged_in == 1) && isset($_POST['myplayers']))  { $plid = ($_POST['myplayers']); $sessu = mysql_escape_string($_SESSION['username']); $result = mysql_query("SELECT id from users WHERE username = '$sess'"); while ($row = mysql_fetch_array($result)) {     $uid = $row['id']; } $plid = ($_POST['myplayers']);     $sql = "INSERT INTO myplayers (user_id, player_id) VALUES ($id, $plid)";     mysql_query ($sql) or die(mysql_error()); } [/code]
  15. Ok, maybe (hopefully) this will show a clearer picture of what I want to do. If the user is logged in with no players currently being tracked, then show this: (the first echo here is the submit botton, a Plus sign image) [code]         echo "<td$row_color align=\"center\"><input type=\"image\" src=\"images/addmyp.gif\" value=\"$player_id\" name=\"myplayers\"></td>";     echo "\t\t<td$row_color><a href='/baseball/players.php?player_id=$player_id'>$fname $lname</td>\n";       echo "\t\t<td$row_color>$mlbteamabbv</td>\n";     echo "\t\t<td$row_color$row_color align=\"center\">$pointsround</td>\n";     echo "\t\t<td$row_color align=\"center\">$gs</td>\n";     echo "\t\t<td$row_color align=\"center\">$cg</td>\n";     echo "\t\t<td$row_color align=\"center\">$wins</td>\n";     echo "\t\t<td$row_color align=\"center\">$losses</td>\n";     echo "\t\t<td$row_color align=\"center\">$saves</td>\n";     echo "\t\t<td$row_color align=\"center\">$ip</td>\n";     echo "\t\t<td$row_color align=\"center\">$ko</td>\n";     echo "\t\t<td$row_color align=\"center\">$bb</td>\n";     echo "\t\t<td$row_color align=\"center\">$ha</td>\n";     echo "\t\t<td$row_color align=\"center\">$sobb</td>\n";     echo "\t\t<td$row_color align=\"center\">$k9</td>\n";     echo "\t\t<td$row_color align=\"center\">$er</td>\n";     echo "\t\t<td$row_color align=\"center\">$era</td>\n";     echo "\t\t<td$row_color align=\"center\">$whip</td>\n";     echo "\t</form></tr>\n";[/code] if the user is logged in and has players tracked in their profile (if myplayer_id = player_id) show a check mark image next to each player being tracked. (if myplayer_id = player_id). Else show the submit button this is the check image next to each player currently being tracked [code] echo "<td$row_color align=\"center\"><img src=\"images/ismyp.gif\" border=\"0\"></td>";[/code] if the user is logged in AND clicks submit on a new player to track, then do this: [code]$sessu = mysql_escape_string($_SESSION['username']); // check to see what the logged in username is $result = mysql_query("SELECT id from users WHERE username = '$sess'"); // finds the user id based on username while ($row = mysql_fetch_array($result)) {     $uid = $row['id']; } $plid = ($_POST['myplayers']);     $sql = "INSERT INTO myplayers (user_id, player_id) VALUES ($id, $plid)";     mysql_query ($sql) or die(mysql_error());   // does the insert into the users table }  [/code] if the user is not logged in AND clicks submit next to one of the players...redirect to the login page [code]if(($logged_in == 0) && isset($_POST['myplayers'])) { header("Location: http://www.fantasybaseballresearch.com/login.php");     echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=/login.php">HERE</a> to be redirected</div></body></html>';     exit;   }  [/code]
  16. [!--quoteo(post=361341:date=Apr 3 2006, 04:45 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 04:45 PM) [snapback]361341[/snapback][/div][div class=\'quotemain\'][!--quotec--] Perhaps I'm not quite understanding correctly, but you can only expect a single match when there can be only 1 $id......that is, the logged in user. [/quote] For example, if a user ($id, correct there can only be one occurence) has selected 10 players to track, this only returns one (the first occurence of $mpid, where mpid is the myplayer_id) record. So, I'm trying to get it to return all of the myplayer_id for that logged in user.
  17. Still can't figure this one out :( Anyone have any ideas?
  18. Indeed you are/were correct. There was a problem with the myplayer_id variable $mpid. Anyway, I got this working and it returns the "if" (the other image) below, but only for the 1st match. Obviously, I would like to have it for all occurences/matches where $mpid == $player_id. [code] <?php $sessu = mysql_escape_string($_SESSION['username']); $result = mysql_query("SELECT id FROM users WHERE username = '$sessu'"); if (!$result) {    die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_array($result)) {     $id = $row['id']; } $result = mysql_query("SELECT player_id FROM myplayers WHERE user_id = '$id'"); if (!$result) {    die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_array($result)) {     $mpid = $row['player_id']; }      echo "<tr>"; if ($logged_in == 1) {   if ($mpid == $player_id)     {     echo "\t\t<td$row_color align=\"center\"><img src=\"images/ismyp.gif\" border=\"0\"></td>\n";     }      else { echo "\t\t<td$row_color align=\"center\"><input type=\"image\" src=\"images/addmyp.gif\" value=\"$player_id\" name=\"myplayers\"></td>\n";         }   }[/code]
  19. Thats probably pretty close. I tried it out and it only shows the else.... I tried this and it only showed the if :) [code]  if  (($logged_in == 1)  && ($myp = $player_id)) {      echo "\t\t<td$row_color align=\"center\"><img src=\"images/ismyp.gif\" border=\"0\"></td>\n"; } else {          echo "\t\t<td$row_color align=\"center\"><input type=\"image\" src=\"images/addmyp.gif\" value=\"$player_id\" name=\"myplayers\"></td>\n"; } [/code] Maybe if provide more info, it will help. Heres my query that selects all the player info for the players, playerstats and teams table [code]$sql = "SELECT ps.*, p.*, t.*         FROM playerstats ps         INNER JOIN         (             players p INNER JOIN mlbteams t             ON t.mlbteam_id = p.mlbteam_id         )         ON ps.player_id = p.player_id         WHERE p.position_id = $set_selected_position         AND ps.year = $set_selected_year         ORDER BY ko DESC";[/code] $player_id = $stat_list[$i]['player_id']; Here is my query selecting the myplayer_id from the myplayers table (this is the one that holds the users players): [code]$result = mysql_query("SELECT * from myplayers WHERE user_id = '$id'"); while ($row = mysql_query($result)) {     $myp = $row['myplayer_id'];      }[/code]
  20. I have a list of basball players. For each player listed, the user has the option to select that player so that they can track them in their profile (I got this part working). The player id in the baseball player table is player_id. In the users table it is myplayer_id. Next to each player there is a submit button that does the insert into the db if selected. What I want to do is...if that player already exists in the users profile..then show a different image...not the submit button for that player. Make sense? Basically (I think) I have to build a query that compares the myplayer_id (in the users table) to the player_id (in the players table. Make sense? IF they match, and the user is logged in ($logged_in == 1) then show this : [code] echo "\t\t<td$row_color align=\"center\"><img src=\"images/ismyp.gif\" border=\"0\"></td>\n"; [/code] if there is no match, then show this: [code]       echo "\t\t<td$row_color align=\"center\"><input type=\"image\" src=\"images/addmyp.gif\" value=\"$player_id\" name=\"myplayers\"></td>\n";[/code] Can someone please help me figure this out. I've been trying for a couple of hours now and I getting pretty pissed :)
  21. Thanks guys...I ended up figuring it out. this works for me. Not sure if it is efficient, but it works. [code]$sessu = mysql_escape_string($_SESSION['username']); $result = mysql_query("SELECT id from users WHERE username = '$sessu'"); if (!$result) {    die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_array($result)) {     $id = $row['id']; } foreach($player_id AS $newp) {     $sql = "INSERT INTO myplayers (user_id, player_id) VALUES ($id, $newp)";     mysql_query ($sql) or die(mysql_error()); }[/code]
  22. Thanks for the reply..session management is definitely working...I did a print_r(_$SESSION) and it returns my username and passwd. Also did an echo"$sql" and it returned my username. What I'm trying to do is get the user id from the above query and use it in the following query, which stores user entered info. The following query is storiing $newp in my db, but not the user id from the first query. Maybe my problem is how I'm using the results from the first query here: [code]foreach($myplayers AS $newp) {     $sql = "INSERT INTO myplayers (user_id, player_id) VALUES ('$id', $newp)";     mysql_query ($sql) or die(mysql_error()); }[/code]
  23. Trying to find the user id from the users table based on the session login name. This is what I have, but its not working. Any pointers? [code] $sessu = $_SESSION['username'];     $sql = "SELECT id from users WHERE username = '$sessu'";[/code]
  24. I'm trying to make a simple form that will allow users to select certain baseball players to add to their profiles. Here is part of my form: [code]<form name="myplayers" method="post" action="insertmyplayers.php"> <?php echo "<TABLE width=\"100%\" border=\"0\">"; echo "<TD align=\"center\" valign=\"top\"><TABLE width=\"100%\" border=\"0\"><TD><div align=\"center\"><div align=\"center\"><h1>Catcher</div></h1>"; $query = "SELECT ps.*,p.*, t.*         FROM playerstats ps         INNER JOIN         (             players p INNER JOIN mlbteams t             ON t.mlbteam_id = p.mlbteam_id         )           ON ps.player_id = p.player_id         AND ps.year = 2005         AND position_id = 1                 ORDER by lname"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) {     $pid =  $row['player_id'];     $lname = $row['lname'];     $fname = $row['fname']; echo "<input name=\"myplayers[];\" type=\"checkbox\" value=\"$pid\">$lname, $fname<br>"; } echo "</TD></TABLE></TD>";[/code] My post page that executes the insert query: [code]foreach($_POST['player_id'] AS $newp) {     $sql = "INSERT INTO myplayers (player_id) VALUES ($newp)";     mysql_query ($sql) or die(mysql_error()); } ?>[/code] I keep getting this error on submission: [code]Warning: Invalid argument supplied for foreach() in[/code] If I select 5 players for the form page. This is what the array looks like: print_r($_POST); [code]Array ( [myplayers] => Array ( [0] => 676 [1] => 677 [2] => 1078 [3] => 1080 [4] => 1089 [5] => 1090 ) [player_id] => )[/code] Any idea what I'm messing up
×
×
  • 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.