cdoyle Posted March 16, 2009 Share Posted March 16, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/ Share on other sites More sharing options...
samshel Posted March 17, 2009 Share Posted March 17, 2009 you require the user to select a car manually so u will require install2. you can pass the install id from first page by query string similarly as u r passing the car id Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/#findComment-786304 Share on other sites More sharing options...
cdoyle Posted March 17, 2009 Author Share Posted March 17, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/#findComment-786317 Share on other sites More sharing options...
samshel Posted March 17, 2009 Share Posted March 17, 2009 <a href=\"car_upgrades.php?act=install2&id=".$_GET['id']."&carid=" . $getcars1['carid'] . "\">" . $getcars1['car_name'] . "</a> r u passing id to install2 url like above? Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/#findComment-786321 Share on other sites More sharing options...
cdoyle Posted March 17, 2009 Author Share Posted March 17, 2009 Would I make a whole other link? Or is there a way to also pass it within the car select link? Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/#findComment-786324 Share on other sites More sharing options...
samshel Posted March 17, 2009 Share Posted March 17, 2009 passing in car select link should do. Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/#findComment-786328 Share on other sites More sharing options...
cdoyle Posted March 17, 2009 Author Share Posted March 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/149735-hold-value-of-variable-througout-switch/#findComment-786331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.