Android App & dropdown MySQL - php

need a lil help.
Taking this example ( http://www.w3schools.com/php/php_ajax_database.asp ), I want to make the same but if you see this part of the code:
form
select name="users" onchange="showUser(this.value)/select
option value=""> Select a person: /option
option value="1"> Peter Griffin /option
option value="2"> Lois Griffin /option
option value="3"> Glenn Quagmire /option
option value="4"> Joseph Swanson /option
/select
/form
Is a static list with values given already.
I want to take out the name values from my DB and create a dropdown list with the array.
My problem is that I already make it in php but android app can't read php, so what can I do?

you can do one thing:
Suppose $data is an array contains the values for drop down.
now,you can do this:
$row=mysql_fetch_assoc();
$data=$row//array containing the values for drop down.
return json_encode($data);

Related

Multiple choice from database without <select>

I'm trying to make a form with Symfony to be able to select multiple choice by checking checkboxes without having a <select> dropdown alone in my form.
Theses choice come from a table in my database, each row must be a choice possibility in my form.
For example table T_Choices :
ID
Choices
1
Choice_1
2
Choice_2
I'm able to create the form with many checkbox as there are rows.
But how can i submit this "dynamic" form and get thoses data in one "array" in my controller to have for example $form["choices"]->getData()[0] or 1 or 2 etc.
Thank you for your help. And sorry for my bad english.
By giving those checkboxes the same value for the name-attribute and adding square brackets at the ending [].
You probably need:
<input id="1" name="choices[]" type="checkbox" value="1"><label for="1">Choice_1</label>
<input id="2" name="choices[]" type="checkbox" value="2"><label for="2">Choice_2</label>

is there a way to group radio button for php usage?

I'm wondering if let's say I have 4 radio buttons named red blue yellow and green but if none of them are unchecked and a person submits the form, let's say will echo no radio checked.
if I use the if statement I can only think of using something like
if(empty($_GET(["red"])) || empty($_GET(["blue"])) || empty($_GET(["green"])) ||empty($_GET(["yellow"])))
{
echo "blah";
}
But that's really long for that if statement if there's two more radio I want to add or something let's say I have a name field an ya....that's gonna be a long long if statement...
is there a way to group them together and make them shorter?
Radio buttons are grouped by default if you give them the same name
<input type="radio" name="group" value="1"> Option 1
<input type="radio" name="group" value="2"> Option 2
The selected option will then be passed to php in $_POST['group']

how to get radio button names based on value

I am building a survey system. I have a page containing 10 items, each item has yes/no options to select. Something like this:
Yes No
1. o o
2. o o
...
<submit>
When I hit submit button, I want to know which items have been selected to yes and no. How can I do that? Thanks.
I know how to retrieve radio button value by name, my question is how to get buttons whose selected value is "yes" and "no". I kinda know how to do it in javascript, but I am not sure how to pass the javascript value back to the PHP script.
If you have something like this
<input type="radio" value="1'"name="radbut">Yes
<input type="radio" value="2" name="radbut">No
the php to select the selected value is like this
$selected=$_GET["radbut"];
I will go into a detailed explanation.
<input type="radio" name="option1" value="Yes"> Yes
<input type="radio" name="option1" value="No"> No
When you're processing this via PHP, there will only be a single "option1" posted value. It will either be Yes, or No, based on which input the user selected.
echo "The user selected: ".$_POST['option1'];
If yes, the above will return:
The user selected: Yes
Same goes for the No.

declaring in PHP application forms w/ radio buttons & check boxes to save

I'm really confused about how to start on my PHP with radio buttons and check boxes.
How do I print out the option chosen by the user?
Also, declaring lots of fields with similar name but with different answers.
It also needs to be connected to a mySQL database.
checkboxes:
<input type="checkbox" name="theoptions[]" value="1"> Option 1...
<input type="checkbox" name="theoptions[]" value="2"> Option 2...
<input type="checkbox" name="theoptions[]" value="3"> Option 3..
.
If user will submit checked 2 & 3 then $_REQUEST['theoptions'] will be array( 2, 3 )
To store in mysql you can create table for selected options for concrete user or implode() that array to store somethin like "2,3" or "2|3"
If you want to save an array in MYSQL I use serialize to save it in the mysql http://www.php.net/manual/en/function.serialize.php
and to get the array back then use http://php.net/manual/en/function.unserialize.php
so it would look like something like
$options=$_GET['theoptions']; //never use $_REQUEST
serialize($options);
//save to mysql database

Insert values from checkboxes in various tables?

wich contains a list of students on the left and a lot of skills to assign to each student.
Each student have it´s own table with the full skill list (HTML, CSS, ...). Now whats a simple way to get value from the checkboxes and assign them to the corresponding student table?
The purpose is to creating a graph for each student showing their skillset :-) ah, sorry for my poor english.
Print the form using a scripting language like PHP. Use a smart naming for checkboxes, then put the logic to retrieve data in the script that receive the post form.
If you use php, u can use
<form>
<input type="checkbox" name="paul[skill1]" value=1>
<input type="checkbox" name="paul[skill2]" value=1>
...
<input type="checkbox" name="robert[skill1]" value=1>
<input type="checkbox" name="robert[skill2]" value=1>
...
</form>
when submitting the page, the $_POST result will be
$POST = array(
[paul] = array( [skill1]=> 1, [skill3]=>1) //paul has skills 1 and 3
[robert] = array( [skill1]=> 1, [skill4]=>1) //paul has skills 1 and 4
)
if you want to do it everything on the frontend, you should use JQuery, but than managing data it's more difficult.
I suppose you have PHP skills, otherwise use a Spreadsheet to do this

Categories