therock1011 Posted April 19, 2010 Share Posted April 19, 2010 Hello, I'm new to php and could use some help with some code. What I am trying to do as per the code below is when someone clicks on the remove or edit link in the code it will load the the corresponding php file once clicked on in the same page as an include or something of that sort. The part I am having trouble with is in the if statement of the code. echo '<table>'; while ($row = mysqli_fetch_array($data)) { // Displays the going mobile data echo '<tr class="goingmobilerow"><td><strong>' . $row['model'] . '</strong></td>'; echo '<td>' . $row['price'] . '</td>'; echo '<td>' . $row['minutes'] . '</td>'; echo '<td>' . $row['monthly'] . '</td>'; echo '<td><a href="removeplan.php?action=remove&id=' . $row['id'] . '&model=' . $row['model'] . '&price=' . $row['price'] . '&minutes=' . $row['minutes'] . '&monthly=' . $row['monthly'] . '&image=' . $row['image'] . '">Remove</a></td>'; echo '<td><a href="editplan.php?action=edit&id=' . $row['id'] . '&model=' . $row['model'] . '&price=' . $row['price'] . '&minutes=' . $row['minutes'] . '&monthly=' . $row['monthly'] . '&image=' . $row['image'] . '">Edit</a></td>'; echo('</tr>'); } echo '</table>'; // if the user clicked on an edit link, spit out the form to edit specific phone/plan if($_GET['action'] == 'edit'){ // include edit script in here } Any help on this is much appreciated. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/ Share on other sites More sharing options...
Jax2 Posted April 19, 2010 Share Posted April 19, 2010 Well, if they're clicking on the link, it looks like it's taking them to a different page, in which case you simply need to get the action ... If it is on the same page, you would use if isset ... I.e. if (isset($_GET['action'])) { $id=$_GET_ID; // INSERT CODE HERE }; Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044707 Share on other sites More sharing options...
therock1011 Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks for the quick reply Jax2. Really appreciate it. Yes currently clicking on the link it takes them to a different page. I understand the isset part however I'm not sure I understand where you are going with the rest of the code. Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044737 Share on other sites More sharing options...
Jax2 Posted April 19, 2010 Share Posted April 19, 2010 I guess I'm not really understanding what you're trying to do then. You're saying you want to include a php file in the page, yet your links open a new page. So are you trying to avoid opening a new page and simply showing the contents of the file on the same page? If so, you'd just do as I showed above ... Use the isset, and then include("whatever.php") inside the brackets. Otherwise, you'll have to go into a little more detail, sorry! Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044740 Share on other sites More sharing options...
therock1011 Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks again Jax2 for replying. Yes you are understanding exactly what it is I am trying to do. I don't want the link to open in a new page, I want it to open in the same page. I tried the include but wouldn't work, still opens in a new page. if (isset($_GET['action'])) { $id=$_GET_ID; include("editplan.php"); }; Also tried this: if (isset($_GET['action'])) { include("editplan.php"); }; Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044745 Share on other sites More sharing options...
Jax2 Posted April 19, 2010 Share Posted April 19, 2010 Your links are set to open in a new page. You need to alter them. You have your link here: <a href="removeplan.php?action=remove&id=' . $row['id'] . '&model=' . $row['model'] . '&price=' . $row['price'] . '&minutes=' . $row['minutes'] . '&monthly=' . $row['monthly'] . '&image=' . $row['image'] . '">Remove</a></td>'; That will open removeplan.php If you want to show this one, for example, on the same page, you would have to open the same page instead of removeplan.php .... For example, if your page is called thispage.php, your link should look like this: <a href="thispage.php?action=remove&id=' . $row['id'] . '&model=' . $row['model'] . '&price=' . $row['price'] . '&minutes=' . $row['minutes'] . '&monthly=' . $row['monthly'] . '&image=' . $row['image'] . '">Remove</a></td>'; And then you would use GET like this: if ($_GET['action']=='remove') { include ("removeplan.php"); } ELSE IF ($_GET['action']=='edit') { include ("editplan.php"); } See what I mean? Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044759 Share on other sites More sharing options...
therock1011 Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks again Jax2. That is exactly what I had in mind but couldn't figure out how to implement it. Anyhow tried that in 2 different ways and still loads in a new page. Here are the 2 sample code I tried: if($_GET['action'] == 'edit'){ include("editplan.php"); } else if($_GET['action'] == 'remove'){ include ("removeplan.php"); } and also tried with the isset: if(isset($_GET['action']) == 'edit'){ include("editplan.php"); } else if(isset($_GET['action']) == 'remove'){ include ("removeplan.php"); } I don't understand why neither one of these works. They make sense and in my opinion should work. Cleared my cache and everything after uploading the changes with still no luck. Maybe something to do with php self might have to be included such as echo $_SERVER['PHP_SELF']; Thanks again. Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044767 Share on other sites More sharing options...
therock1011 Posted April 19, 2010 Author Share Posted April 19, 2010 thanks for your help Jax2. One thing I didn't notice in your code was that you changed removeplan.php to thispage.php so I changed thispage.php to my index.php page and it worked as this is the page that all this code is on, index.php. Really appreciate your help problem solved. Thanks again Link to comment https://forums.phpfreaks.com/topic/199029-new-to-php-and-need-some-help/#findComment-1044774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.