Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with sessions

    Hi all, I posted in the ajax section about this problem but since it's actually related to the php file I thought I better post here.

    Anyway, I have a script that gets the best odds value for the 1, X, 2 for a game when I click a + picture.

    However there is a problem. If I choose (1) for two games and then a (X) from another game all other games in the list get (X) also.

    I want to be able to choose (1) from two games and then (X) or (2) from another game.

    The testpage url is: http://cjhweb.se/Oddstest/oddstest2.php

    This is the php script I have so far:

    PHP Code:
    <?php
    session_start
    ();

    $game_id $_GET[game_id]; //the game id from the URL
    $action $_GET[action]; //the action from the URL
    $oddstype $_GET[oddstype]; //the action from the URL


    if ($oddstype == "odds1")
    {
    $oddstypes =  "`Odds_1`, `Odds_1_Unibet`";
    $oddsname "(1)";
    }

    else if (
    $oddstype == "odds2")
    {
    $oddstypes =  "`Odds_2`, `Odds_2_Unibet`";
    $oddsname "(2)";
    }
    else if (
    $oddstype == "oddsX")
    {
    $oddstypes =  "`Odds_X`, `Odds_X_Unibet`";
    $oddsname "(X)";
    }

    //if there is an product_id and that product_id doesn't exist display an error message
    if($game_id && !gameExists($game_id)) {
        die(
    "Error. Game Doesn't Exist");
    }

    switch(
    $action) { //decide what to do

        
    case "add":
        
    $_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
        
    break;

        case 
    "remove":
            
    $_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

            
    if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
        
    break;

        case 
    "empty":
            unset(
    $_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
        
    break;

    }


    if(
    $_SESSION['cart']) { //if the cart isn't empty
    //show the cart

        
    echo "<table border=\"1\" padding=\"3\" width=\"40%\">"//format the cart using a HTML table

        //iterate through the cart, the $game_id is the key and $quantity is the value
        
    foreach($_SESSION['cart'] as $game_id => $quantity) {

            
    //get the name, description and price from the database - this will depend on your database implementation.
            //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

           
    $sql sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

           
    $result mysql_query($sql) or die("Query error: "mysql_error());
           if(
    mysql_num_rows($result) > 0) { 
           
            
    //Only display the row if there is a product (though there should always be as we have already checked)
           

                
    list( $gamename$odds_expekt$odds_unibet) = mysql_fetch_row($result);

                
    $line_cost_expekt $odds_expekt//work out the line cost
                
    $line_cost_unibet $odds_unibet;
                
                
    $total_expekt $total_expekt $line_cost_expekt//add to the total cost
                
    $total_unibet $total_unibet $line_cost_unibet;
                
                if (
    $odds_expekt $odds_unibet)
                {
                
    $line_cost_best $line_cost_expekt;
                }
                
                else if (
    $odds_unibet $odds_expekt)
                {
                
    $line_cost_best $line_cost_unibet;
                }    
                
                echo 
    "<tr>";
                
    //show this information in table cells
                
    echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
                
    //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                
    echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
                echo 
    "<td align=\"center\">$line_cost_best</td>";

                echo 
    "</tr>";


    }
        }

        
    //show the total
        
    echo "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
        echo 
    "<td align=\"right\">$total_expekt</td>";
        echo 
    "</tr>";
        
        echo 
    "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
        echo 
    "<td align=\"right\">$total_unibet</td>";
        echo 
    "</tr>";
        
        
    //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
        
    echo "<tr>";
        echo 
    "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
        echo 
    "</tr>";
        echo 
    "</table>";

    }

    else{
    //otherwise tell the user they have no items in their cart
        
    echo "Du har inte valt några matcher.";
    }



    //function to check if a product exists
    function gameExists($game_id) {
        
    //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
        
    $sql sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id); 

        
        return 
    mysql_num_rows(mysql_query($sql)) > 0;
    }
    ?>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply, but I'm afraid it's still the same problem: http://cjhweb.se/Oddstest/oddstest2.php

    This is a hard one...

  • #4
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope it should be $oddstype.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    You'll have to insert some "echo" statements to monitor what is happening.
    I have no way to test anything.

  • #6
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure what you mean. When you click on a + pic it should echo results from the php file.

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    I mean ...

    For testing ...

    Put some echo statements in your script so you can see
    what different variables are ...

    Like ...

    list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);
    echo "gamename: $gamename<br>";
    echo "odds_expekt: $odds_expekt<br>";



    In key locations .... to see what might be causing it to be read or assigned wrong.
    Just for testing ... take them out, and move them around.

  • #8
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, added some echoes: http://cjhweb.se/Oddstest/oddstest2.php

    PHP Code:

    <?php

    $game_id 
    $_GET[game_id]; //the game id from the URL
    $action $_GET[action]; //the action from the URL
    $oddstype $_GET[oddstype]; //the action from the URL

    echo "GET[game_id]: $_GET[game_id]<br>";
    echo 
    "GET[action]: $_GET[action]<br>";
    echo 
    "GET[oddstype]: $_GET[oddstype]<br>";


    if(
    $oddstype == "odds1"){
    $oddstypes =  "`Odds_1`, `Odds_1_Unibet`";
    $oddsname "(1)";
    echo 
    "odds1: $odds1<br>";

    }

    if(
    $oddstype == "odds2"){
    $oddstypes =  "`Odds_2`, `Odds_2_Unibet`";
    $oddsname "(2)";
    echo 
    "odds2: $odds2<br>";

    }

    if(
    $oddstype == "oddsX"){
    $oddstypes =  "`Odds_X`, `Odds_X_Unibet`";
    $oddsname "(X)";
    echo 
    "oddsX: $oddsX<br>";

    }  

    //if there is an product_id and that product_id doesn't exist display an error message
    if($game_id && !gameExists($game_id)) {
        die(
    "Error. Game Doesn't Exist");
    }

    switch(
    $action) { //decide what to do

        
    case "add":
        
    $_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
        
    break;

        case 
    "remove":
            
    $_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id
            
    if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
        
    break;

        case 
    "empty":
            unset(
    $_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
        
    break;

    }

    ?>

    <?php

    if($_SESSION['cart']) { //if the cart isn't empty
    //show the cart
    echo "Latest game_id: $game_id<br>";
        echo 
    "<table border=\"1\" padding=\"3\" width=\"40%\">"//format the cart using a HTML table

        //iterate through the cart, the $game_id is the key and $quantity is the value
        
    foreach($_SESSION['cart'] as $game_id => $quantity) {
    echo 
    "quantity: $quantity<br>";
            
    //get the name, description and price from the database - this will depend on your database implementation.
            //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

           
    $sql sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

           
    $result mysql_query($sql) or die("Query error: "mysql_error());
           if(
    mysql_num_rows($result) > 0) { 
           echo 
    "result: $result<br>";
            
    //Only display the row if there is a product (though there should always be as we have already checked)
           

                
    list( $gamename$odds_expekt$odds_unibet) = mysql_fetch_row($result);
    echo 
    "game_id: $game_id<br>";
    echo 
    "gamename: $gamename<br>";
    echo 
    "odds_expekt: $odds_expekt<br>";
    echo 
    "odds_unibet: $odds_unibet<br>";
                
    $line_cost_expekt $odds_expekt//work out the line cost
                
    $line_cost_unibet $odds_unibet;
    echo 
    "line_cost_expekt: $line_cost_expekt<br>";
    echo 
    "line_cost_unibet: $line_cost_unibet<br>";        
                
    $total_expekt $total_expekt $line_cost_expekt//add to the total cost
                
    $total_unibet $total_unibet $line_cost_unibet;
    echo 
    "total_expekt: $total_expekt<br>";
    echo 
    "total_expekt: $total_unibet<br>";                    
                if (
    $odds_expekt $odds_unibet)
                {
                
    $line_cost_best $line_cost_expekt;
                echo 
    "line_cost_best if Expekt: $line_cost_expekt<br>";        
                }
                
                else if (
    $odds_unibet $odds_expekt)
                {
                echo 
    "line_cost_best if Unibet: $line_cost_unibet<br>";        
                
    $line_cost_best $line_cost_unibet;
                }    
                
                echo 
    "<tr>";
                
    //show this information in table cells
                
    echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
                
    //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                
    echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Remove</a></td>";
                echo 
    "<td align=\"center\">$line_cost_best</td>";

                echo 
    "</tr>";


    }
        }

        
    //show the total
        
    echo "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
        echo 
    "<td align=\"right\">$total_expekt</td>";
        echo 
    "</tr>";
        
        echo 
    "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
        echo 
    "<td align=\"right\">$total_unibet</td>";
        echo 
    "</tr>";
        
        
    //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
        
    echo "<tr>";
        echo 
    "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
        echo 
    "</tr>";
        echo 
    "</table>";



    }else{
    //otherwise tell the user they have no items in their cart
        
    echo "Du har inte valt några matcher.";

    }
    ?>

    <?php
    //function to check if a product exists
    function gameExists($game_id) {
        
    //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
        
    $sql sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id); 

        
        return 
    mysql_num_rows(mysql_query($sql)) > 0;
    }
    ?>

  • #9
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe I'm using the wrong method here. I'm trying to make this like a shopping cart but since there are different oddstypes, do I have to use database? Or can I still use sessions?
    Last edited by Calle81; 11-18-2010 at 12:49 AM.

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    no ... not like that.

    The purpose is to echo variables so you can try to figure-out
    why they are all changing when you select the 2nd one.

    Run this one ...
    PHP Code:
    <?php
    session_start
    ();

    $game_id $_GET[game_id]; //the game id from the URL
    $action $_GET[action]; //the action from the URL
    $oddstype $_GET[oddstype]; //the action from the URL


    if ($oddstype == "odds1")
    {
    $oddstypes =  "`Odds_1`, `Odds_1_Unibet`";
    $oddsname "(1)";
    }

    else if (
    $oddstype == "odds2")
    {
    $oddstypes =  "`Odds_2`, `Odds_2_Unibet`";
    $oddsname "(2)";
    }
    else if (
    $oddstype == "oddsX")
    {
    $oddstypes =  "`Odds_X`, `Odds_X_Unibet`";
    $oddsname "(X)";
    }

    //if there is an product_id and that product_id doesn't exist display an error message
    if($game_id && !gameExists($game_id)) {
        die(
    "Error. Game Doesn't Exist");
    }

    switch(
    $action) { //decide what to do

        
    case "add":
        
    $_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
        
    break;

        case 
    "remove":
            
    $_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

            
    if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
        
    break;

        case 
    "empty":
            unset(
    $_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
        
    break;

    }


    if(
    $_SESSION['cart']) { //if the cart isn't empty
    //show the cart

        
    echo "<table border=\"1\" padding=\"3\" width=\"40%\">"//format the cart using a HTML table

        //iterate through the cart, the $game_id is the key and $quantity is the value
        
    foreach($_SESSION['cart'] as $game_id => $quantity) {

            
    //get the name, description and price from the database - this will depend on your database implementation.
            //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

           
    $sql sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

           
    $result mysql_query($sql) or die("Query error: "mysql_error());
           if(
    mysql_num_rows($result) > 0) { 
           
            
    //Only display the row if there is a product (though there should always be as we have already checked)
           

                
    list( $gamename$odds_expekt$odds_unibet) = mysql_fetch_row($result);
                 
                 
                
    // See what is happening here ...
                
    echo"
                rows found: "
    .mysql_num_rows($result)." <br>
                gamename is: $gamename <br>
                oddsname is: $oddsname <br>
                game id is: $game_id <br>
                "
    ;
                
                
    // Halt the script so you can see the results ...
                
    exit;
                
                
                
    $line_cost_expekt $odds_expekt//work out the line cost
                
    $line_cost_unibet $odds_unibet;
                
                
    $total_expekt $total_expekt $line_cost_expekt//add to the total cost
                
    $total_unibet $total_unibet $line_cost_unibet;
                
                if (
    $odds_expekt $odds_unibet)
                {
                
    $line_cost_best $line_cost_expekt;
                }
                
                else if (
    $odds_unibet $odds_expekt)
                {
                
    $line_cost_best $line_cost_unibet;
                }    
                
                echo 
    "<tr>";
                
    //show this information in table cells
                
    echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
                
    //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                
    echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
                echo 
    "<td align=\"center\">$line_cost_best</td>";

                echo 
    "</tr>";


    }
        }

        
    //show the total
        
    echo "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
        echo 
    "<td align=\"right\">$total_expekt</td>";
        echo 
    "</tr>";
        
        echo 
    "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
        echo 
    "<td align=\"right\">$total_unibet</td>";
        echo 
    "</tr>";
        
        
    //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
        
    echo "<tr>";
        echo 
    "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
        echo 
    "</tr>";
        echo 
    "</table>";

    }

    else{
    //otherwise tell the user they have no items in their cart
        
    echo "Du har inte valt några matcher.";
    }



    //function to check if a product exists
    function gameExists($game_id) {
        
    //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
        
    $sql sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id); 

        
        return 
    mysql_num_rows(mysql_query($sql)) > 0;
    }
    ?>
    </body>
    </html>
    Last edited by mlseim; 11-18-2010 at 01:16 AM.

  • #11
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I appreciate your help on this

    I added your code and this is the result: http://cjhweb.se/Oddstest/oddstest2.php

    I'm still kinda lost though.

  • #12
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    OK ...

    When I run that script (the link you gave us),
    and I click on any of them, it is always displaying
    the same gamename: FC København - Rosenborg BK

    Why is that?

    I would expect the "gamename" to be whatever I clicked.

    So, is that possibly a clue?

    ============

    Now, take the "exit" out of there .... remove the red part ...

    // See what is happening here ...
    echo"
    rows found: ".mysql_num_rows($result)." <br>
    gamename is: $gamename <br>
    oddsname is: $oddsname <br>
    game id is: $game_id <br>
    ";

    // Halt the script so you can see the results ...
    exit;



    See if that gives you some more clues on what is happening.




    .
    Last edited by mlseim; 11-18-2010 at 03:05 AM.

  • #13
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I noticed that too. It only changed the oddstype. I removed the red line and now it is like it was before.

    http://cjhweb.se/Oddstest/oddstest2.php

  • #14
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    So now when I run your script, I see what is happening ...

    It puts the same oddsname into every entry.
    But the ID is correct, the gamename is correct, and it correctly finds 1 row each time.

    So, we actually have a good clue now as to where the problem might be.

    I want you to try this script now ...

    Try this and let me see what it does:
    PHP Code:
    <?php
    session_start
    ();

    $game_id $_GET[game_id]; //the game id from the URL
    $action $_GET[action]; //the action from the URL
    $oddstype $_GET[oddstype]; //the action from the URL


    if ($oddstype == "odds1")
    {
    $oddstypes =  "`Odds_1`, `Odds_1_Unibet`";
    $oddsname "(1)";
    }

    else if (
    $oddstype == "odds2")
    {
    $oddstypes =  "`Odds_2`, `Odds_2_Unibet`";
    $oddsname "(2)";
    }
    else if (
    $oddstype == "oddsX")
    {
    $oddstypes =  "`Odds_X`, `Odds_X_Unibet`";
    $oddsname "(X)";
    }

    //if there is an product_id and that product_id doesn't exist display an error message
    if($game_id && !gameExists($game_id)) {
        die(
    "Error. Game Doesn't Exist");
    }

    switch(
    $action) { //decide what to do

        
    case "add":
        
    $_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
        
    break;

        case 
    "remove":
            
    $_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

            
    if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
        
    break;

        case 
    "empty":
            unset(
    $_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
        
    break;

    }


    if(
    $_SESSION['cart']) { //if the cart isn't empty
    //show the cart

        
    echo "<table border=\"1\" padding=\"3\" width=\"40%\">"//format the cart using a HTML table

        //iterate through the cart, the $game_id is the key and $quantity is the value
        
    foreach($_SESSION['cart'] as $game_id => $quantity) {

            
    //get the name, description and price from the database - this will depend on your database implementation.
            //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

           
    $sql sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

           
    $result mysql_query($sql) or die("Query error: "mysql_error());
           if(
    mysql_num_rows($result) > 0) { 
           
            
    //Only display the row if there is a product (though there should always be as we have already checked)
           

                
    list( $gamename$odds_expekt$odds_unibet) = mysql_fetch_row($result);
                 
                if (
    $oddstypes ==  "`Odds_1`, `Odds_1_Unibet`"){
                
    $oddsname "(1)";
                }
                else if (
    $oddstypes ==  "`Odds_2`, `Odds_2_Unibet`"){
                
    $oddsname "(2)";
                }
                else if (
    $oddstypes ==  "`Odds_X`, `Odds_X_Unibet`"){
                
    $oddsname "(X)";
                }
                  
                
    $line_cost_expekt $odds_expekt//work out the line cost
                
    $line_cost_unibet $odds_unibet;
                
                
    $total_expekt $total_expekt $line_cost_expekt//add to the total cost
                
    $total_unibet $total_unibet $line_cost_unibet;
                
                if (
    $odds_expekt $odds_unibet)
                {
                
    $line_cost_best $line_cost_expekt;
                }
                
                else if (
    $odds_unibet $odds_expekt)
                {
                
    $line_cost_best $line_cost_unibet;
                }    
                
                echo 
    "<tr>";
                
    //show this information in table cells
                
    echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
                
    //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                
    echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
                echo 
    "<td align=\"center\">$line_cost_best</td>";

                echo 
    "</tr>";


    }
        }

        
    //show the total
        
    echo "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
        echo 
    "<td align=\"right\">$total_expekt</td>";
        echo 
    "</tr>";
        
        echo 
    "<tr>";
        echo 
    "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
        echo 
    "<td align=\"right\">$total_unibet</td>";
        echo 
    "</tr>";
        
        
    //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
        
    echo "<tr>";
        echo 
    "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
        echo 
    "</tr>";
        echo 
    "</table>";

    }

    else{
    //otherwise tell the user they have no items in their cart
        
    echo "Du har inte valt några matcher.";
    }



    //function to check if a product exists
    function gameExists($game_id) {
        
    //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
        
    $sql sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id); 

        
        return 
    mysql_num_rows(mysql_query($sql)) > 0;
    }
    ?>
    </body>
    </html>

  • #15
    New Coder
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oki, added the code. Output seems to be the same as the first script: http://cjhweb.se/Oddstest/oddstest2.php


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •