473,480 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

If yes then echo this, if no echo that in PHP-simple array?

10 New Member
Hello,

Can anyone help me complete this? Is this an array?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $Choice1 = $_POST['Choice1'];
  3. $Choice2 = $_POST['Choice2'];
  4. $Nothing = $_POST['Nothing']
  5.  
I have an HTML file that will have a radio button and a text input
that looks like this.

Would you like to help me?
Yes or No
If yes, post choice 1
if no, post choice 2.
If left blank show nothing.....
Jan 28 '10 #1
13 5043
rdbrock
10 New Member
please go easy on me, i'm new :)
Jan 28 '10 #2
Dormilich
8,658 Recognized Expert Moderator Expert
doesn’t assigning the appropriate values do the trick?
Jan 28 '10 #3
rdbrock
10 New Member
well, sorry about this, I failed to mention that I would like to have a multiple question. Would be like this.

Would you like to help me now?
If yes , post choice 1
if no , ask another question.
Thanks for helping, please choose 2 options
Yes or no.

Then post :

# $Choice1 = $_POST['Choice1'];
# $Choice2 = $_POST['Choice2'];
# $Nothing = $_POST['Nothing']
Jan 28 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
what does the according HTML look like? (hard to imagine right now)
Jan 28 '10 #5
rdbrock
10 New Member
does that make any sence?

I'm just trying to ask a question if value" NO" then SHOW " another question"
if YES or NO then display $whatever value.....

I would only like the second question to display only if you selected "NO" so it will need to hide. Is this possible with PHP ? or do I need a JAVA script?
Jan 28 '10 #6
rdbrock
10 New Member
I'm not exactly sure to ask the 2nd question in HTML or I guess to hide it

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5.  <form form action="help.php" method="post"> 
  6. <form>
  7.  
  8.  
  9. <b>Would you like to help me?</b>  
  10.  
  11.  <input type="radio" name="group1" value="Yes"> Yes<br>
  12. <input type="radio" name="group2" value="Water"> No<br>
  13.  
  14.  <input name="Choice1" type="text" /> 
Jan 28 '10 #7
code green
1,726 Recognized Expert Top Contributor
You need common name attributes when using radio buttons
Expand|Select|Wrap|Line Numbers
  1. <input type="radio" name="group" value="Yes"> Yes<br>
  2. <input type="radio" name="group" value="Water"> No<br>
  3.  
Jan 28 '10 #8
rdbrock
10 New Member
Thanks for correcting that. Is there a way to hide a question in HTML?
Jan 28 '10 #9
zorgi
431 Recognized Expert Contributor
I am not sure if this code is here just by copy/paste accident

Expand|Select|Wrap|Line Numbers
  1. <form form action="help.php" method="post">
  2. <form>
  3.  
but just in case it probably should look like this:

Expand|Select|Wrap|Line Numbers
  1. <form action="help.php" method="post">
  2. </form>
  3.  
Notice closing <form></form>
And also all of your form elements (like radios) should be within those tags. Now.... I do not think this are php issues at all
Jan 28 '10 #10
rdbrock
10 New Member
Thanks, for that , that was a typo too. I'm just not good at details :) I do have the script working just fine,my problem is that I'm trying to incorporate if you choose "NO" on the radio button, I'd like for a HTML/PHP to show another "Text" or "Ask " another question. I'm thinking about a list function. But it did not work, how I wanted it to. Perhaps I don't know what function it suitable for what I am trying to accomplish.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $my_array = array(Yes","No","Nothing");
  3.  
  4. list($Choice1, $Choice2, $Nothing) = $my_array;
  5. echo "You selected Choice #2, the 2nd question would should here $Choice1, a $Choice1 and a $Nothing.";
  6. ?> 
I feel like I'm still missing something here.
Jan 28 '10 #11
rdbrock
10 New Member
I think I may have got it.
Could I use this or is there another easier way to do this?
Example 1 question depending on answer ask another question and so on.

Expand|Select|Wrap|Line Numbers
  1. >?php
  2. $my_array = array("My Question #1 ","My Question # 2"," No question-blanks");
  3.  
  4. list($a, , $c) = $my_array;
  5. echo "Here I only use the $a and $c variables.";
  6. ?>
  7.  
  8. The output of the code above will be:
  9. Here I only use the My Question #1 and No question-blanks.
  10.  
Jan 28 '10 #12
rdbrock
10 New Member
Zorgi or code green, would you guys be able to help me understand how to get a Multiple Yes or No Question in HTML to work with the array I built using selective questions if chosen " no or "yes" to show the output on the array following another question
to display anything on the array?
I think this would solve the problem, if the List function /array is the way to go for Yes or No, then multiple questions based on yes or no selection.

Thanks much!
Jan 28 '10 #13
rdbrock
10 New Member
Or anyone else that understands in this matter.
Jan 29 '10 #14

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

Similar topics

3
2661
by: Michael Flanagan | last post by:
Of course "echo" is working, but I've got a case where php doesn't seem to be sending out the result of an "echo." I'm probably doing something wrong, but I can't see it. I've got the following...
6
2373
by: Marco | last post by:
I have a couple pages that have tables, whats best use echo to produce the full table with the variables or is it best to just make the table in plain html and use <?php echo ('$va'l); ?> when i...
9
3400
by: Domestos | last post by:
Here an unusual one... Say i am writing a few lines of code in php script as so... <?php echo '<table>'; echo '<tr>'; echo '<td> blah blah </td>'; echo '</tr>'; echo '</table>';
10
2094
by: M | last post by:
Hi, Suppose you have the situation where you have say 20 blocks of text (~250 chars each) in a MySQL db that you need to display, but each has a condition to check to see whether you should...
25
3079
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
1
1532
Odisey
by: Odisey | last post by:
Hello, I am still getting these concepts. Help me learn. What is wrong here? Most echos are for testing. Thank you, Odisey <?php #index php script 3.4
4
1695
by: prosad | last post by:
hi; i have two tables in MySQL with: 1. TABLE(stat) column(c_id, FOREIGN KEY) referencing 2. TABLE (complaint) column (id_complaint, PRIMARY KEY). TABLE (complaint) also contain a second...
4
1993
by: rawky1976 | last post by:
Hi, I have a hyperlink which goes to the page below and passes the PK_ID from a query into 'userid'. From this we query the DB and then echo a table with a form; only the textboxes are already...
1
5621
by: webandwe | last post by:
Hi, I got the page login.php that have a script that logs you in and then go to loggedin.php with a piece of code to validate your loged in. The validate stores the username, how can I echo the...
32
2593
by: Request-1 | last post by:
hi folks, html coder here, new and terrified * of php!! aaaaaa! i'm trying to bury a JS script to rotate a photo, in a page i converted from html to php. the conversion went well, it was to...
0
7051
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
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7097
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
6750
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
6993
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...
0
5353
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,...
0
3003
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...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
193
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...

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.