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!
Hello everyone!
I'm a newbie in php and i need some help .I have a dropdown select where i select an user (from a table -> date_clienti). I want to print out (in the same page where is located the dropdown menu) the rest of the information about the selected user ,from the same table (name,second-name,telephone,address...) .How can I do that? Tables are created in mysql .
I read some solution from this forum like viewtopic.php?t=30174&highlight=repopulate but I need some example please with code.Thank yuou for your patience!
<html>
<head>
<title></title>
</head>
<body>
<table align="center" border="1" cellspacing="10">
<tr>
<td>
<form name="myform" method="post" action="delete.php">
<select name="varclient_id" onChange="">
<option selected value="">
<?
include ("../conectare.php");
$sql="select client_id,name,second_name from date_clienti order by name asc";
$rezultat=mysql_query($sql);
$nr_rows=mysql_num_rows($rezultat);
if ($varclient_id>0) {
$varclientid=$varclient_id;
}
if ((isset($varclient_id) and ($varclient_id!=($nr_rows+1)) and ($varclient_id>0))) {
$populare=mysql_query("SELECT client_id,name,second_name from date_clienti where client_id=$varclient_id order by name asc");
$var_pop=mysql_fetch_array($populare);
$varclient_id=$var_pop['client_id'];
$n=$var_pop['name'];
$pren=$var_pop['second_name'];
echo("$n  $pren");
echo("<option value=($nr_rows+1)>Client\n");
}
else {
echo ("Client");
$varclient_id=($nr_rows+1);
}
$populare=mysql_query("SELECT client_id,name,second_name from date_clienti where client_id!=$varclient_id order by name asc");
while ($repopulare=mysql_fetch_array($populare)) {
$varclient_id=$repopulare['client_id'];
$n=$repopulare['name'];
$pren=$repopulare['second_name'];
echo("<option value='$varclient_id'>$n  $pren\n");
}
mysql_close;
?>
</select>
<input type="submit" value="Delete">
</form>
</td></tr>
</table>
</body>
</html>
line 13: the onchange needs to be set, if you want the page to automatically change upon the person selected someone.
your code assumes register_globals are on. Register globals have been off for close to three years now, by default. Be careful with that.
provided register globals are on, I don't see much wrong with your code. Although currently, you are writing the "selected" user's information into the drop down, and not outside it, like you probably want...
Maybe i'm not asking the right question... I want when I select the user from the dropdown ,to write those aditional information (from the table) in same page.For example when I select the name of an user to apper in a text box the address, telephone, ... of this user.Yes must be set onchange() but...here I'm stuck...
When I submit the form I call a scrip delete.php who delete what I'm select from drop-down...and I don't want to delete only when I see the aditional information who I trying to print out. After seeing this info I decide if I delete the user selected or not.
have the delete script do a confirmation, displaying the information. You should have that anyways if the person viewing the page has Javascript turned off..
i have a similar problem. Right, now i'm using this.form.submit() and what i'm trying to do is to populate a textarea a text field and a selection box, and this part works.
Now my situation is that the guy i'm doing this for want to have whatever selected in the first selection box still to be highlighted/shown in selection box, after selecting a choice.
My question is: Can this be done withot using alot of java script? (which is not a force of mine)