473,473 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to pass variable to a second tab

123 New Member
i have a page which is home.php on that page i have a CSS tab which is tab1 and tab2 on that page in both tabs i have a link called next that pass variable to the next page (<a href='home.php?page=$lastpage'>NEXT</a>).if i click on next in the tab1 on home page(home.php) it will pass the variable and bring me to the home page and tab1 if i click on the next in tab2 it will also bring me to home page and take me to tab1 back.i want it to bring meto the home page and tab2 how can i do that.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title></title>
  5. <link href="SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
  6.  
  7. <?php
  8. if (isset($_GET['page'])) {
  9. $pages = ($_GET['page']);
  10. } else {
  11. echo "page one";
  12. }
  13. ?>
  14.  
  15. <ul class="TabbedPanelsTabGroup">
  16. <li class="TabbedPanelsTab" tabindex="0">Tab1</li>
  17. <li class="TabbedPanelsTab" tabindex="0">Tab2</li>
  18. </ul>
  19.  
  20. <div class="TabbedPanelsContent">
  21. <div class="tabb">
  22. <?php
  23. echo "<a href='home.php?page=$lastpage'>NEXT</a>";
  24. ?>
  25. </div></div>
  26.  
  27. <div class="TabbedPanelsContent">
  28. <div class="tab">
  29. <?php
  30. echo "<a href='home.php?page=$lastpage'>NEXT</a>";
  31. ?>
  32. </div></div>
  33.  
  34. </head>
  35. </html>
  36.  
Oct 9 '09 #1
12 6811
Dormilich
8,658 Recognized Expert Moderator Expert
er, could you rephrase your question please, I didn’t get what you want.
Oct 9 '09 #2
simon2x1
123 New Member
i want tab2 to display if i click on the link Next in tab2 it should not take me back to tab1
Oct 10 '09 #3
TheServant
1,168 Recognized Expert Top Contributor
So you need to track which tab you're on. Either making a $_SESSION variable to include current_tab or something, or using $_POST / $_GET...

I would go with $_SESSION so you don't have to submit to move pages ($_POST) and you don'r have to change URLs ($_GET).
Oct 11 '09 #4
simon2x1
123 New Member
@TheServant
how can i track the tab and also make a $_SESSION variable to include current_tab
Jul 13 '10 #5
TheServant
1,168 Recognized Expert Top Contributor
@simon2x1
You should read up on $_SESSION's, but they are very similar to other variables. You could also use $_COOKIE's which will be able to remember which tab they're on even if they close the browser and come back in a week.
Expand|Select|Wrap|Line Numbers
  1. // To set a session variable:
  2. $_SESSION['current_tab'] = "About Tab";
  3. // To recall a session variable:
  4. if ($_SESSION['current_tab'] == $current_tab_name) {
  5. echo "selected";
  6. }
  7.  
That conditional statement can obviously be anything and you would use it to show a css property, or call a javascript function or however you're tracking which tab to display.

Also when you're using sessions you need to tell PHP you're going to be using sessions on every page. You need to put this line at the top of every page that will use the $_SESSION super variable:
Expand|Select|Wrap|Line Numbers
  1. session_start();
Jul 13 '10 #6
simon2x1
123 New Member
i still did not get it well help me take a look at my code below and tell me what the problem his
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. session_start();
  5. $_SESSION['TabbedPanelsTab'] = "About Tab";
  6. if ($_SESSION['TabbedPanelsTab'] == $current_tab_name) { 
  7. echo "selected"; 
  8. }   
  9. ?>
  10.  
  11. <html> 
  12. <head> 
  13. <title></title> 
  14. <link href="SpryTabbedPanels.css" rel="stylesheet" type="text/css" /> 
  15.  
  16. <?php 
  17. if (isset($_GET['page'])) { 
  18. $pages = ($_GET['page']); 
  19. } else { 
  20. echo "page one"; 
  21. ?> 
  22.  
  23. <ul class="TabbedPanelsTabGroup"> 
  24. <li class="TabbedPanelsTab" tabindex="0">Tab1</li> 
  25. <li class="TabbedPanelsTab" tabindex="0">Tab2</li> 
  26. </ul> 
  27.  
  28. <div class="TabbedPanelsContent"> 
  29. <div class="tabb"> 
  30. <?php 
  31. echo "<a href='home.php?page=$lastpage'>NEXT</a>"; 
  32. ?> 
  33. </div></div> 
  34.  
  35. <div class="TabbedPanelsContent"> 
  36. <div class="tab"> 
  37. <?php 
  38. echo "<a href='home.php?page=$lastpage'>NEXT</a>"; 
  39. ?> 
  40. </div></div> 
  41.  
  42. </head> 
  43. </html> 
  44.  
  45.  
  46.  
Jul 21 '10 #7
TheServant
1,168 Recognized Expert Top Contributor
Where do you get your $current_tab_name? There is no definition there?

To get into more specifics, the question is how do you intend on changing tabs? Will your tabs be different pages, or will all content be loaded and then tabs only show selected content. The second option is more user friendly, but will require javascript, and will not be great for SEO and page tracking.

If you are reloading every time a tab is changed, maybe session variables will not be ideal and a nicer $_GET variable will be easier, as you probably don't want to start doing AJAX functions between changing pages... Maybe you do? If it's just changing tabs, a $_GET should be fine, and with some .htaccess tricks, you can make pretty URL's.
Jul 22 '10 #8
simon2x1
123 New Member
the tabs are on the same page not different pages am talking about the content of the tabs i want the content of tab2 to display when ever i click submit button in the content of tab2 not to take me back to tab1.
Oct 2 '10 #9
Dormilich
8,658 Recognized Expert Moderator Expert
the submit button does not take you back to tab1. it just loads the page with the default setting, which is probably tab1.
Oct 2 '10 #10
kovik
1,044 Recognized Expert Top Contributor
If you have these tabs inside of one page, I'd recommend doing one of two things:
  1. Using the query string and $_GET, or
  2. Using JavaScript to display the tabs.

Session data is for preserving data across page requests. What you are making IS a page request, and does not represent data that should persist across requests. What you want to do is, basically, just make your tabs into links. Plain and simple.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $active_tab = isset($_GET['tab']) ? (int)$_GET['tab'] : 0;
  3. $tabs = array(
  4.   1 => 'Tab 1',
  5.   2 => 'Tab 2',
  6. );
  7. ?>
  8. <ul id="tabs>
  9.   <?php foreach ($tabs as $tab_id => $tab_name): ?>
  10.   <li<?php if ($active_tab == $tab_id) echo ' class="active"'; ?>>
  11.     <a href="?tab=<?php echo $tab_id; ?>"><?php echo $tab_name; ?></a>
  12.   </li>
  13.   <?php endforeach; ?>
  14. </ul>
  15. <div id="tab-content">
  16. <?php if ($active_tab == 1): ?>
  17. This content is in tab #1.
  18. <?php elseif ($active_tab == 2): ?>
  19. This content is in tab #2.
  20. <?php else: ?>
  21. The tab that you have selected is invalid. Sneaky, sneaky.
  22. <?php endif; ?>
  23. </div>
Then, you'd style the tabs with CSS and add whatever other logic you want.
Oct 4 '10 #11
simon2x1
123 New Member
i want to thank you for your reply i will appreciate it if i will be able to use JavaScript to solve this problem using this php code make me more confess please i need the java script version that can solve this problem
Oct 23 '10 #12
kovik
1,044 Recognized Expert Top Contributor
I'm sorry, but if you can't do this yourself, chances are trying to explain how to use my code would go over your head anyway. Good luck, though.
Oct 25 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: eagletender | last post by:
I am simply trying to pass a variable to another page. I know my second page can do Request("str") to retrieve that variable, but how do I pass it in the first place? I tried...
12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
7
by: Morgan | last post by:
I have read much posts on the argument but no one clearly says if this operation is possible or not. Simply I have a routine which reads from a text file some integer arrays (1 or 2D). The...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
7
by: RayAll | last post by:
I have an array of one of my classes (Client myarray) ,I'd like to pass this array to a static method of a class for further processing what dose the calling Methods signature look like? ...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
2
by: prakashgkhaire | last post by:
i have two structure where first structure consists val and structure pointer(linklist), 2nd structure consists, val, a varialbe of first structure, pointer of structure. Now i found to pass the...
10
arunmib
by: arunmib | last post by:
hi all, I just got this freaky kind of doubt....I have the following piece of code, int main() { int Val= 10, *ptr; ptr = &Val; TestFn(&Val);
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.