Jump to content

jktress

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jktress's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am creating a fantasy formula 1 game. Sanfly helped me out, but I can't seem to get the right values inserted into my table. Instead, this code inserts blank rows into my table (20 or so of them) I can't seem to figure out the trouble. I select a race date and the variable is sent in the URL to race.php. Then I enter appropriate driver points into a table called driverPoints in a mySQL database. [code] <?php require_once('Connections/formula1.php'); //select a database @mysql_select_db($database_formula1) or die( "Unable to select database"); //the query is set to a variable $q = "SELECT * FROM circuits ORDER BY race_date"; //the result of the query is set to a variable $r = mysql_query($q) or die(mysql_error()); //the fetch_array loop is looking through the results of my query and returning all the rows! It looks like it is storing them in two variables    while($row = mysql_fetch_array($r)){       $race_name = $row['circuitName'];       $race_id = $row['race_id'];       $race_date = $row['race_date'];          echo "$race_name - $race_date (<a href=\"races.php?action=addpoints&rid=$race_id\">Add Points</a>)<br>";    } ?> [/code] Here is the form where I enter the points the drivers earned during the race. [code] <?php //get the race id and set it to a variable $rId = $_GET['rId']; //double check that you are coming from the post page if($_GET['action'] = "addpoints" && $_GET['rId'] == $rId){ ?>     <form method="post" action="races.php?action=addpoints2">         <table>             <tr>                 <td>Driver name</td>                     <td>Points</td>             </tr> <? require('Connections/formula1.php'); @mysql_select_db($database_formula1) or die( "Unable to select database"); $q = "SELECT * FROM drivers";     $r = mysql_query($q) or die(mysql_error());            while($row = mysql_fetch_array($r)){               $driver_id = $row['driver_id'];               $driver_name = $row['nameD']; ?>              <tr>                                <td><?=$driver_name?> <input type="hidden" name="rp_driver[]" value="<?=$driver_id?>"></td>                     <td><input type="text" name="rp_points[]" size="10"></td>             </tr>          <?    } ?>             <tr>                 <td colspan="2">                     <input type="hidden" name="rp_race" value="<?=$rId?>">                     <input type="submit" value="Update the Points">                 </td>             </tr>                  </table>     </form> <?php     } if($_GET['action'] = "addpoints2"){     // Get Posted Variables     $rp_race = $_POST['rp_race'];     $rp_driver = $_POST['rp_driver'];     $rp_points = $_POST['rp_points'];          $dp = array();     $dp['driver'] = $rp_driver;     $dp['points'] = $rp_points;     $num = count($dp);     for($i = 0; $i < $num; $i ++){         $dp_driver = $dp['driver'][$i];         $dp_points = $dp['points'][$i];                  require('Connections/formula1.php');         @mysql_select_db($database_formula1) or die( "Unable to select database");         $q = "INSERT INTO driverPoints (rp_race, rp_driver, rp_points) VALUES ('$rp_race', '$rp_driver', '$rp_points')";         $r = mysql_query($q) or die(mysql_error());     }          echo "done, link to whatever here"; }?> [/code] I have gone through the code a few times and still can't seem to figure out the problem. Any ideas?
  2. Ok I have the pages up, I believe I understand the code pretty well. I'm having some trouble getting the values inserted into my driverPoints table however, and I can't find the problem. It is inserting 10 blank rows. [code] <?php $rId = $_GET['rId']; if($_GET['action'] = "addpoints" && $_GET['rId'] == $rId){ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body>     <form method="post" action="races.php?action=addpoints2">         <table>             <tr>                 <td>Driver name</td>                     <td>Points</td>             </tr> <? require('Connections/formula1.php'); @mysql_select_db($database_formula1) or die( "Unable to select database"); $q = "SELECT * FROM drivers";     $r = mysql_query($q) or die(mysql_error());            while($row = mysql_fetch_array($r)){               $driver_id = $row['driver_id'];               $driver_name = $row['nameD']; ?>              <tr>                                <td><?=$driver_name?> <input type="hidden" name="rp_driver[]" value="<?=$driver_id?>"></td>                     <td><input type="text" name="rp_points[]" size="10"></td>             </tr>        <?    } ?>             <tr>                 <td colspan="2">                     <input type="hidden" name="rp_race" value="<?=$rId?>">                     <input type="submit" value="Update the Points">                 </td>             </tr>                  </table>     </form> <?php     } if($_GET['action'] = "addpoints2"){     // Get Posted Variables     $rp_race = $_POST['rp_race'];     $rp_driver = $_POST['rp_driver'];     $rp_points = $_POST['rp_points'];          $dp = array();     $dp['driver'] = $rp_driver;     $dp['points'] = $rp_points;     $num = count($dp);     for($i = 0; $i < $num; $i ++){         $dp_driver = $dp['driver'][$i];         $dp_points = $dp['points'][$i];                  require('Connections/formula1.php');         @mysql_select_db($database_formula1) or die( "Unable to select database");         $q = "INSERT INTO driverPoints (rp_race, rp_driver, rp_points) VALUES ('$rp_race', '$rp_driver', '$rp_points')";         $r = mysql_query($q) or die(mysql_error());     }          echo "done, link to whatever here"; }?> [/code] yes, the users pick a team, but they stick with that team throughout the entire season and earn points based on driver, chassis, and engine performance.
  3. great, thanks very much for the help.. It's going to take me a while to wrap my brain around this! I'll go through the code and try to figure out each piece. Now I also have to calculate points for engines and chassis's. The users get 2 drivers, 1 engine, and 1 chassis. I have tables set up exactly like the drivers table above, (ie. Engine_ID, Engine_Name, Engine_Price). I need to be able to update the points for those as well. Scores from drivers, engine, and chassis are combined for a total. Would you recommend a similar solution as in your above post?
  4. [!--quoteo(post=369532:date=Apr 28 2006, 06:30 AM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Apr 28 2006, 06:30 AM) [snapback]369532[/snapback][/div][div class=\'quotemain\'][!--quotec--] Are you using a mysql database? have you set up any tables yet? If so, what tables and structure have you used so far? [/quote] I have set up a users table, drivers table, driverPoints table. I was hoping to relate the driverPoints table to the drivers table structure of the driver points table is as follows (driver ID(Primary Key), race1, race2...etc) [!--quoteo(post=369535:date=Apr 28 2006, 06:41 AM:name=jktress)--][div class=\'quotetop\']QUOTE(jktress @ Apr 28 2006, 06:41 AM) [snapback]369535[/snapback][/div][div class=\'quotemain\'][!--quotec--] I have set up a users table, drivers table, driverPoints table. I was hoping to relate the driverPoints table to the drivers table structure of the driver points table is as follows (driver ID(Primary Key), race1, race2...etc) [/quote] I'm using a MySQL database, with phpmyadmin
  5. I'm very new to php and attempting to build a formula 1 fantasy site. I have created an admin page, and would like to be able to update the amount of points each driver has accumulated during the race via a form. There are 23 drivers, and therefore I need to update 23 rows in a single column each weekend. I have tried to save the $_POST method and update my table that way, however I don't think a single variable can hold all the data...I believe I need to use an array (in addition to the $_POST array) however I'm not sure how to implement this. Can anyone help me out?
×
×
  • 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.