PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
farid
Forum Commoner
Posts: 54 Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico
Post
by farid » Fri Sep 30, 2005 11:18 am
Hi y'all!!
Well here it goes, I have in a web page two radiobuttons, and (this part I do not know how to do it ), it suppose to load info from a database according to the selection of the radio into a select, that is if someone selects the first radiobutton it loads info from one table into the select, and if the second radio is selected, then it loads info from a second table in the same select.
Hoping someone can help me!!
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Fri Sep 30, 2005 1:27 pm
Code: Select all
<input type='radio' name='myradio' value='rowone' />
<input type='radio' name='myradio' value='rowtwo' />
Code: Select all
$valid = array('rowone','rowtwo');
if (in_array($_GET['myradio'],$valid)) { // these two steps are IMPORTANT!!
$query = "SELECT {$_GET['myradio']} FROM mytb";
}
farid
Forum Commoner
Posts: 54 Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico
Post
by farid » Fri Sep 30, 2005 1:44 pm
Ok, thanks man, I´ll check it right away!!
farid
Forum Commoner
Posts: 54 Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico
Post
by farid » Fri Sep 30, 2005 2:01 pm
MMh well I do not know but it does not work, my code
Code: Select all
<body>
<table width="430" align="center">
<tr>
<td >Operacion</td>
<td><div>
<input type="radio" name="operacion" value="propuesta">
Nueva Propuesta</strong></font></div>
<div>
<input type="radio" name="operacion" value="actualizacion">
Actualización de Equipos</div></td>
</tr>
<tr>
<td >Plataforma*</td>
<td>
<input type="radio" name="plataforma" value="GSM">
GSM
<input type="radio" name="plataforma" value="TDMA">
TDMA </td>
</tr>
<tr>
<td>Marca
y Modelo</td>
<td <input name="marca_modelo" type="text" id="marca_modelo" size="20" maxlength="20">
</td>
<td width="165" bgcolor="#24A2C6"><select name="menu1" id="menu1">
<option>Selecciona la Propuesta</option>
<?php
$valid = array('propuesta','actualiza');
if (in_array($_GET['operacion'],$valid)) { // these two steps are IMPORTANT!!
@$link_id = mysql_connect("[hostname]", "[login]", "[password]") or die("Connection Failed");
$select_db = mysql_select_db("[database]",$link_id) or die("Connection Failed");
$obtiene_gsm=mysql_query("SELECT marca_modelo FROM akit_GSM WHERE propuesta='1' ORDER BY marca_modelo") or die ("No hay propuestas disponibles");
while ($despliega_gsm=mysql_fetch_array($obtiene_gsm)){
print "<option>".$despliega_gsm["promocion"];
}
}else{
@$link_id = mysql_connect("[hostname]", "[login]", "[password]") or die("Connection Failed");
$select_db = mysql_select_db("[database]",$link_id) or die("Connection Failed");
$obtiene_gsm=mysql_query("SELECT marca_modelo FROM akit_TDMA WHERE propuesta='1' ORDER BY marca_modelo") or die ("No hay propuestas disponibles");
while ($despliega_gsm=mysql_fetch_array($obtiene_gsm)){
print "<option>".$despliega_gsm["promocion"];
}
}
?>
</select></td>
</tr>
<tr>
<td height="25" bgcolor="#1C6295"><strong><font color="#FFFFFF" size="2" face="Arial">Promoción</font></strong></td>
<td height="25" bgcolor="#24A2C6"><strong><font color="#000000" size="2" face="Arial">
<input name="promocion" type="text" id="promocion" value="-" size="20" maxlength="40">
</font></strong></td>
<td height="25" bgcolor="#24A2C6"><select name="menu2" id="menu2">
<option>Selecciona la Promoción</option>
<?php
@$link_id = mysql_connect("[hostname]", "[login]", "[password]") or die("Connection Failed");
$select_db = mysql_select_db("[database]",$link_id) or die("Connection Failed");
$res_gsm=mysql_query("SELECT promocion FROM akit_GSM WHERE propuesta='1'") or die ("No hay propuestas disponibles");
while ($obten_gsm=mysql_fetch_array($res_gsm)){
print "<option>".$obten_gsm["promocion"];
}?>
</select></td>
</tr>
<tr>
<td height="25" colspan="3"> </td>
</tr>
<tr>
<td height="25" colspan="3"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<body>
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Fri Sep 30, 2005 2:19 pm
<input type="radio" name="operacion" value="actualizacion">
$valid = array('propuesta','actualiza');
And I'd take out your username and password on the connect line... -_-'
farid
Forum Commoner
Posts: 54 Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico
Post
by farid » Fri Sep 30, 2005 5:05 pm
Ok, I've already fix it, but in the select does not appear the info, oh about the login and password there is no prob, the server is in a LAN connection, thanks.