php-general Digest 26 Jun 2011 14:34:49 -0000 Issue 7376
Topics (messages 313719 through 313722):
dropdown with two Sql query
313719 by: asp kiddy
313722 by: Jim Giner
Re: [PHP-DB] Re: radio form submission
313720 by: Tamara Temple
313721 by: Tamara Temple
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hi,
have some difficulty with my 'select'
In my select/menu, I display all the options come from a table (table_db_email)
in my database
In this table (tb_code_prmtn11_email) I have two field :
fld_email_id
fld_name_email
It works here is a code
------------code-------------------->
<select name="email_adress_menu" id="email_adress_menu" class="valid"
onchange="submit()">
<?php
echo "<option selected=\"selected\" value=''>Choose your name</option>";
$req_email_adress_menu = "SELECT DISTINCT id_email, fld_name_email,
fld_adresse_email FROM $table_db_email ORDER BY fld_name_email ";
$rep_email_adress_menu = mysql_query($req_email_adress_menu, $cnx) or die(
mysql_error() ) ;
while($show_email_adress_menu = mysql_fetch_assoc($rep_email_adress_menu)) {
echo '<option value="'.$show_email_adress_menu['id_email'].'"';
//if($primes==$show_email_adress_menu['fld_name_email']){echo " selected";}
//display to select an option!!!!!!!!!!!!!!!!
echo '>'.$show_email_adress_menu['fld_name_email'].' -
'.$show_email_adress_menu['fld_adresse_email'].'</option>';
}
?>
</select>
<-----end----code--------------------
I have some other information coming from another table : tb_code_prmtn11
(containing information about people)
I have a few fields :
id_resultat
fld_name
fld_email_id; ( FOREIGN KEY (fld_email_id) REFERENCES tb_code_prmtn11_email
(id_email) ON DELETE NO ACTION ON UPDATE CASCADE;)
I want to put this menu on another Web page and this select must display all of
the options as below( with) BY SELECTING THE OPTION THAT MATCHES THE
INFORMATION FOUND IN THE SECOND TABLE : tb_code_prmtn11
How can I do this ?
------------code-------------------->
SELECT td.id_resultat,td.fld_email_id,email.fld_name_email
FROM $table_db td
JOIN $table_db_email email ON td.fld_email_id = email.id_email
WHERE td.id_resultat = $id
<-----end----code--------------------
This code works also but I don't know how I can include this second query in my
menu...
Do you have an idea for me ?
--- End Message ---
--- Begin Message ---
I don't even understand what the first two code blocks are saying. Looks
like html, but I have never seen it like that. I also don't see the two
fields you specifically mention to start in your first select statement -
some other garbled names are there instead. Are you sure you've copied this
correctly?
"asp kiddy" <[email protected]> wrote in message
news:[email protected]...
In this table (tb_code_prmtn11_email) I have two field :
fld_email_id
fld_name_email
It works here is a code
------------code-------------------->
<select name="email_adress_menu" id="email_adress_menu" class="valid"
onchange="submit()">
<?php
echo "<option selected=\"selected\" value=''>Choose your name</option>";
$req_email_adress_menu = "SELECT DISTINCT id_email, fld_name_email,
fld_adresse_email FROM $table_db_email ORDER BY fld_name_email ";
$rep_email_adress_menu = mysql_query($req_email_adress_menu, $cnx) or
die( mysql_error() ) ;
while($show_email_adress_menu = mysql_fetch_assoc($rep_email_adress_menu))
{
echo '<option value="'.$show_email_adress_menu['id_email'].'"';
//if($primes==$show_email_adress_menu['fld_name_email']){echo "
selected";} //display to select an option!!!!!!!!!!!!!!!!
echo '>'.$show_email_adress_menu['fld_name_email'].' -
'.$show_email_adress_menu['fld_adresse_email'].'</option>';
}
?>
</select>
<-----end----code--------------------
--- End Message ---
--- Begin Message ---
On Jun 24, 2011, at 1:44 PM, Chris Stinemetz wrote:
#### radio select validation ####
What I am doing wrong?
I want to make sure a radio button is selected, but my current code
allows insertion even when radio button isn't selected.
At the risk of repeating myself:
From: Tamara Temple <[email protected]>
Date: June 23, 2011 7:41:12 PM CDT
To: php-db list <[email protected]>
Subject: Re: [PHP-DB] radio form submission
You can also avoid the problem with an empty return if no radio
button is checked by making sure one is checked when your form
loads, by using the 'checked' attribute on one of the items. If you
want them to have a "not tested" option, you can include that as one
of your buttons and add it to the array above as well. (That might
be a good place to use the zero value.)
My code is:
//Generating radio buttons for store type with
array
echo 'Store type:<br /><br />';
$choices = array('corporate' =>
'Cricket owned | ',
'premier'
=> 'Premier dealer');
$firstchecked=FALSE;
foreach
($choices as $key => $choice) {
if (!$firstchecked) {
echo "<input type='radio' name='store_type' value='$key'
checked /> $choice".PHP_EOL;
$firstchecked = TRUE;
} else {
echo
"<input type='radio' name='store_type' value='$key'/>
$choice \n";
}
}
//Validate the radio button submission
if
(!array_key_exists($_POST['store_type'], $choices)) {
echo
"You must select a valid choice.";
}
That's rather brute-force; perhaps some maven can come up with a
better scheme.
--- End Message ---
--- Begin Message ---
On Jun 24, 2011, at 2:20 PM, Jim Giner wrote:
Call me backwards, but I prefer to keep my statements simple. I
would first
obtain the POST value before trying to pull up an array element.
$stype=$_POST[''store_type'];
if (!isset($stype))
(handle missing radio button)
else
$st_name=$choices[$stype];
for me (and the next guy who has to look at the code) this is
simpler to
follow, IMHO.
Yeah, probably true, also probably saves a bit on dereferencing, dunno
how PHP interprets things.
--- End Message ---