Jump to content

Recommended Posts

Hi,

I think I'm just going about this the wrong way, but I'll try and describe what I'm doing.

 

In my game,  I have a page that displays their inventory (inventory.php).  Some of the inventory are car parts.  From this page, they can select to install these parts to one of their cars.

 

So on the inventory page I have a link to car_upgrades.php

The link looks like this.

    echo "<a href=\"car_upgrades.php?act=install&id=" . $item['id'] . "\">Install</a><br />";

 

This works fine it takes them to the install case, and runs a quick check to make sure they actually own that part.

 

 

$installid = $_GET['id'];
//verify install id belongs to player
$verify1 = $db->execute("SELECT `addon_id` FROM `car_upgrade_owned` WHERE `player_id`=? and `addon_id`=?", array($player->id, $installid));


if ($getcars->recordcount() == 0)
{
    echo "You don't own any cars, what ya planning on putting these parts?<br><a href=\"home.php\">Home</a>";
}
else
{
    switch ($_GET['act'])

    {
        case "install":

            if(isset($installid) && (is_numeric($installid) && $installid > 0))
            {
                if ($verify1->recordcount() == 0)
                {
                    echo "You don't own this part";
                }
                else
                {
                    Echo "Please Select a car that you would like to install this part on<br>";
                    echo "<table width='50%' border='1'>";
                    echo "<tr>";
                    while($getcars1 = $getcars->fetchrow())
                    {
                        echo "<tr><td><a href=\"car_upgrades.php?act=install2&carid=" . $getcars1['carid'] . "\">" . $getcars1['car_name'] . "</a></td></tr>";
                    }
                    echo "</table>";
                }

            }
            else
            {
                echo "invalid input";

            }
            break;
        case "install2":
            $carid = $_GET['carid'];

            //verify car belongs to player
            $verifycar =  $db->execute("SELECT c.id, i.car_owned_id FROM cars_owned c
                                        LEFT JOIN impound i ON i.car_owned_id=c.id
                                        WHERE c.player_id=? and c.id=?", array($player->id, $carid ));

            if ($verifycar->recordcount() == 0)
            {
                echo "You don't own this car";

            }
            else if ($verify1 ->recordcount() == 0)
            {
                echo "You don't own this part";
                echo $installid;
            }

 

The part I'm getting stuck is having the user select the car they want to install the part on.

You'll see in the code above, I'm running a query to get the players cars. 

 

The name of the car is a link holds the carid..

<a href=\"car_upgrades.php?act=install2&carid=" . $getcars1['carid'] . "\">" . $getcars1['car_name'] . "</a>

 

So this is where I'm not sure how to proceed.  Should the link take them to a new switch case?  install2?  Or is there a better way to do this?

 

If it should go to install2,  I'm not sure how to make it remember the actual $installid that it carried over from the inventory.php page.

 

Would this be a session variable? 

 

Or can I do this all within the first install switch case and no need for install2?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/
Share on other sites

Thanks for replying,

 

OK, so I'm on the right track.

I have this at the start of my page

$installid = $_GET['id'];

 

Inside the first case 'install' it works fine,  but it doesn't want to work within install2.

 

I can echo $installid within the install case, but when I try to do the same in install2.  It doesn't echo anything.

 

Do you see anything in my code above that would cause that?

 

 

I've never thought about passing 2 variables within a link before.

   echo "<tr><td><a href=\"car_upgrades.php?act=install2&carid=" . $getcars1['carid'] . "&installid=" . $installid ."\">" . $getcars1['car_name'] . "</a></td></tr>";

 

that seems to work. 

 

Thank you again!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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