473,788 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to show table based on variable?

I want to display a table on a page based on whether a button is
pressed or not. I'm new at php so I'm sure I'm making a basic
mistake. Here's what I am trying. My thought was that $show_summary
would switch states with each click but it is coming up always true.
So I'm guessing that is the default setting when the page loads. Can
someone please point out where I am going wrong?

if(isset($_POST['summary'])) {
$show_summary = true;
} else {
$show_summary = false;
}

<FORM method="POST" action="testpag e.php">
<INPUT type="submit" name="summary" value="Show Summary">
</FORM>

<?php if ($show_summary == true) { ?>
<table border="1" cellpadding="3" >
<tr>
<td class="smallTex t" align="center" width="80%"><?p hp echo "URL";
?></td>
</tr>
</table>
<?php } ?>

Jack
Jul 17 '05 #1
11 2317
Jack wrote:
I want to display a table on a page based on whether a button is
pressed or not.
If the button is not pressed, how does PHP receive the data?
I'm new at php so I'm sure I'm making a basic
mistake. Here's what I am trying. My thought was that $show_summary
would switch states with each click but it is coming up always true.
So I'm guessing that is the default setting when the page loads. Can
someone please point out where I am going wrong?
You have to have a way to post the form /other/ than the submit button
named "summary".

You can do that with another submit button (or maybe with JavaScript).

if(isset($_POST['summary'])) {
$show_summary = true;
} else {
$show_summary = false;
}

<FORM method="POST" action="testpag e.php">
<INPUT type="submit" name="summary" value="Show Summary">

<INPUT type="submit" name="no_summar y" value="Don't Show Summary">

</FORM>

<?php if ($show_summary == true) { ?>
<table border="1" cellpadding="3" >
<tr>
<td class="smallTex t" align="center" width="80%"><?p hp echo "URL";
?></td>
</tr>
</table>
<?php } ?>


HTH

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
On 27 May 2004 10:29:58 -0700, ve****@twmi.rr. com (Jack) wrote:
I want to display a table on a page based on whether a button is
pressed or not. I'm new at php so I'm sure I'm making a basic
mistake. Here's what I am trying. My thought was that $show_summary
would switch states with each click but it is coming up always true.
So I'm guessing that is the default setting when the page loads. Can
someone please point out where I am going wrong?

if(isset($_POS T['summary'])) {
$show_summary = true;
} else {
$show_summary = false;
}

<FORM method="POST" action="testpag e.php">
<INPUT type="submit" name="summary" value="Show Summary">
</FORM>

<?php if ($show_summary == true) { ?>
<table border="1" cellpadding="3" >
<tr>
<td class="smallTex t" align="center" width="80%"><?p hp echo "URL";
?></td>
</tr>
</table>
<?php } ?>

Jack


Keep things more simple...

You don't need the FORM.

Just put an anchor in with a value in the GET data - e.g.
<a href='page.php? field=x'>button </a>

Then check $_GET["field"] to see if it's got anything in it.

If you do use a form,

<form method='POST' action='page.ph p'>
<input type='hidden' name='field' value='x'>
<input type='submit'>
</form>

then in the page, access
$_POST["field"] to see if theres anything in it
Regards

Jonathan Beckett
jonbeckett_at_p luggedout.com
http://www.pluggedout.com/blog
Jul 17 '05 #3
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...
Jack wrote:
I want to display a table on a page based on whether a button is
pressed or not.


If the button is not pressed, how does PHP receive the data?
I'm new at php so I'm sure I'm making a basic
mistake. Here's what I am trying. My thought was that $show_summary
would switch states with each click but it is coming up always true.
So I'm guessing that is the default setting when the page loads. Can
someone please point out where I am going wrong?


You have to have a way to post the form /other/ than the submit button
named "summary".

You can do that with another submit button (or maybe with JavaScript).

if(isset($_POST['summary'])) {
$show_summary = true;
} else {

$show_summary = false;
}

<FORM method="POST" action="testpag e.php">
<INPUT type="submit" name="summary" value="Show Summary">

<INPUT type="submit" name="no_summar y" value="Don't Show Summary">

</FORM>

<?php if ($show_summary == true) { ?>
<table border="1" cellpadding="3" >
<tr>
<td class="smallTex t" align="center" width="80%"><?p hp echo "URL";
?></td>
</tr>
</table>
<?php } ?>


HTH


Thanks for the help. This does work. I'll look into your suggestion
about javascript too since I would really rather have just the one
button.

Jack
Jul 17 '05 #4
Jon Beckett <jonbeckett@nos pam_yahoo.co.uk > wrote in message news:<r5******* *************** **********@4ax. com>...
On 27 May 2004 10:29:58 -0700, ve****@twmi.rr. com (Jack) wrote:
I want to display a table on a page based on whether a button is
pressed or not. I'm new at php so I'm sure I'm making a basic
mistake. Here's what I am trying. My thought was that $show_summary
would switch states with each click but it is coming up always true.
So I'm guessing that is the default setting when the page loads. Can
someone please point out where I am going wrong?

if(isset($_POS T['summary'])) {
$show_summary = true;
} else { $show_summary = false;
}

<FORM method="POST" action="testpag e.php">
<INPUT type="submit" name="summary" value="Show Summary">
</FORM>

<?php if ($show_summary == true) { ?>
<table border="1" cellpadding="3" >
<tr>
<td class="smallTex t" align="center" width="80%"><?p hp echo "URL";
?></td>
</tr>
</table>
<?php } ?>

Jack


Keep things more simple...

You don't need the FORM.

Just put an anchor in with a value in the GET data - e.g.
<a href='page.php? field=x'>button </a>

Then check $_GET["field"] to see if it's got anything in it.


I tried this but, probably due to my inexperience, I don't see the
difference. If I click on the link and $_GET returns an x, then that
could be the "on" setting. Then, when I click on it again, I need it
to be turned off. But $_GET will still return an x won't it? Am I
totally missing the point?
If you do use a form,

<form method='POST' action='page.ph p'>
<input type='hidden' name='field' value='x'>
<input type='submit'>
</form>

then in the page, access
$_POST["field"] to see if theres anything in it

As I mentioned, I'm new at this so I am probably missing the obvious,
but can you explain to me how $_POST["field"] checks for two different
values since the form is only submitting one?

Regards

Jonathan Beckett
jonbeckett_at_p luggedout.com
http://www.pluggedout.com/blog

Jul 17 '05 #5
Jack wrote:
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...
Jack wrote:
> I want to display a table on a page based on whether a button is
> pressed or not.
If the button is not pressed, how does PHP receive the data?

Thanks for the help. This does work. I'll look into your suggestion
about javascript too since I would really rather have just the one
button.


I still don't understand how you're going to submit a form without
pressing a button :-)
Try this:

========
<?php
$hidden = 1;
$show_form = true;
$show_summary = false;
$show_thanks = false;
if (isset($_POST['hidden'])) {
if ($_POST['hidden'] == '1') { $hidden = 2; $show_summary = true; }
if ($_POST['hidden'] == '2') { $hidden = 3; $show_form = false; $show_thanks = true; }
}

if ($show_form) {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="hidden" value="<?php echo $hidden; ?>"/>
text: <input type="text" name="text" value="text"/>
<input type="submit"/>
</form>
<?php
}

if ($show_summary) {
?>
<br/><br/>Summary:<br/>
The text you entered is: [<strong><?php echo $_POST['text']; ?></strong>]<br/>
<?php
}

if ($show_thanks) {
?>
<p>Thank you!</p>
<p>Turn your computer off, and go read a book.</p>
<?php
}
?>
========

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #6
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...
Jack wrote:
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...
Jack wrote:
> I want to display a table on a page based on whether a button is
> pressed or not.

If the button is not pressed, how does PHP receive the data?
Thanks for the help. This does work. I'll look into your suggestion
about javascript too since I would really rather have just the one
button.


I still don't understand how you're going to submit a form without
pressing a button :-)


I'm not really wanting to submit a form. That was the only way I
could think of to try to do what I wanted. All I want is a button
that acts as an on/off switch. Press it once and a table is
displayed. Press it again and the table is hidden.
Try this:

========
<?php
$hidden = 1;
$show_form = true;
$show_summary = false;
$show_thanks = false;
if (isset($_POST['hidden'])) {
if ($_POST['hidden'] == '1') { $hidden = 2; $show_summary = true; }
if ($_POST['hidden'] == '2') { $hidden = 3; $show_form = false; $show_thanks = true; }
}

if ($show_form) {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="hidden" value="<?php echo $hidden; ?>"/>
text: <input type="text" name="text" value="text"/>
<input type="submit"/>
</form>
<?php
}

if ($show_summary) {
?>
<br/><br/>Summary:<br/>
The text you entered is: [<strong><?php echo $_POST['text']; ?></strong>]<br/>
<?php
}

if ($show_thanks) {
?>
<p>Thank you!</p>
<p>Turn your computer off, and go read a book.</p>
<?php
}
?>
========


I do appreciate you taking the time to enter this code but it is
getting farther away from what I need.

Jack
Jul 17 '05 #7
Jack wrote:
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...
Jack wrote:
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...

Jack wrote:

>I want to display a table on a page based on whether a button is
>pressed or not.

If the button is not pressed, how does PHP receive the data?

Thanks for the help. This does work. I'll look into your suggestion
about javascript too since I would really rather have just the one
button.


I still don't understand how you're going to submit a form without
pressing a button :-)

I'm not really wanting to submit a form. That was the only way I
could think of to try to do what I wanted. All I want is a button
that acts as an on/off switch. Press it once and a table is
displayed. Press it again and the table is hidden.

If you don't mind using javascript and css:

<script type="text/javascript">
var visibility = 'hidden';
function toggleTable()
{
if( visibility == 'visible' ) visibility = 'hidden';
else visibility = 'visible';

document.getEle mentById('myTab le').style.cssT ext =
'visibility: ' + visibility;
}
</script>

<table id="myTable" style="visibili ty: hidden">
<tr><th>My Table</th></tr>
</table>

<input type="button" onclick="toggle Table()" value="table">
--
-Moxley
moxleystratton. com
Jul 17 '05 #8
Jack wrote:
I'm not really wanting to submit a form. That was the only way I
could think of to try to do what I wanted. All I want is a button
that acts as an on/off switch. Press it once and a table is
displayed. Press it again and the table is hidden.


As Moxley said you can do it with JavaScript.
If you want to do it with PHP, I think your best bet is to use a session
variable and toggle it with each submit. Then check that toggle and send
(or do not send) the table to the browser; something like:
<?php
session_start() ;
if (!isset($_SESSI ON['table_toggle'])) $_SESSION['table_toggle'] = true;

if (isset($_POST['submit_button'])) {
// reverse table_toggle
$_SESSION['table_toggle'] = !$_SESSION['table_toggle'];
}

if ($_SESSION['table_toggle']) {
// send table to browser
}
?>

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #9
I'm not really wanting to submit a form. That was the only way I
could think of to try to do what I wanted. All I want is a button
that acts as an on/off switch. Press it once and a table is
displayed. Press it again and the table is hidden.


Can't you use javascript?

<input id='thebutton' type='submit' value='show' onClick='return
showtable()'>
<table id='thetable' style='display: none'>
...
...
</table>

<script language='javas cript'>
function showtable() {
b = document.getEle mentById('thebu tton');
t = document.getEle mentById('theta ble');
if (b.value == 'show') {
b.value = 'hide';
t.style.display = '';
} else {
b.value = 'show';
t.style.display = 'none';
}
}
</script>
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1795
by: Anne M | last post by:
I have a report based on query..which is a team list with names and their role on team ie coach, assistant and player. Report is almost what I want and my knowledge is limited so I need some advice. I want the team list to show the names of the individuals and their role on team if they are coach or assistant but not if they are player but since they are based on the same field (role) how do I set it so I can get it to show only what...
3
2609
by: Lynn | last post by:
Hello, I have a user control that contains a table, and some text fields. I would like to show or hide a particular row of this table, based on a selection the user makes on my page. Here's the situation...I have a page that has some panels that are hidden. The first panel is visible...the user selects a city, and presses submit. The next panel is made visible, and in this panel I have placed a user
2
2723
by: Steve Bottoms | last post by:
Hi, all! Using VB as code-behind in asp.net page... I have a TABLE control which I'm building dynamically. After the table is built, I'm trying to retrieve the HEIGHT property of that table (table.height.value) to be able to dynamically position the next elements on the form. However, this control property is coming back as -0- every time. I also try to get the table height with Javascript after-the-fact (table.style.height), but that...
4
1393
by: robmarleh | last post by:
Hi, I've been trying to set up a php system to calculate and order and recieve delivery address/s. It's going pretty well so far but I having trouble with one particular part. I've been trying to use a for loop to show a number of delivery address forms based on the quantity of the product ordered, (sounds like a strange thing to do but the product is intended for people so send to friends as a novelty item) I have created a php file of...
9
3063
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
2
3896
by: banderson | last post by:
Hello, I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg mgmt company names and then to open a building management company form to show all records with this name, so the user can find the correct branch location to select. Then, upon closing the building management company form, the active/selected record...
5
4475
by: Mike P | last post by:
How would I show or hide a div that is using client side Javascript based upon a server side variable? Here are my divs : <div id="idButton5" class="otherLeftBarLink" onmouseover="javascript: changeStylesMouseOver('5');" onmouseout="javascript: changeStylesMouseOut('5');" onclick="location='/AddProject.aspx'"> <div class="leftBarLinkText"> Add Project
1
1630
by: filch | last post by:
Hi, I am new to this forum ... so hello to all! I am trying to get a script working which will show or hide a table based on a user checking or unchecking a parent checkbox. This is the script I have come up with so far (note that one of my issues is whether or not you can use an if/else construct inside of a case statement): function showIt($id) { alert("ID is : $id"); switch ($id) {
1
3813
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown properties alt in img tag istead of picture . place of the pictures is saved in the database(my database is with mysql) and in home page i fetch properties of the product and address of place that pictures is located output of the code in the...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.