repopulate...?

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

Post Reply
leroiv
Forum Newbie
Posts: 3
Joined: Tue Apr 19, 2005 4:54 am

repopulate...?

Post by leroiv »

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!

Code: Select all

<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&nbsp&nbsp$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&nbsp&nbsp$pren\n");
	}

mysql_close;
?>
</select>
<input type="submit" value="Delete">
</form>
</td></tr>
</table>
</body>
</html>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by leroiv on Tue Apr 19, 2005 8:39 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  • 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...
leroiv
Forum Newbie
Posts: 3
Joined: Tue Apr 19, 2005 4:54 am

Post by leroiv »

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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

so you want to submit the form when a person is selected?

Code: Select all

onchange=&quote;this.form.submit()&quote;
leroiv
Forum Newbie
Posts: 3
Joined: Tue Apr 19, 2005 4:54 am

Post by leroiv »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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..
thallish
Forum Commoner
Posts: 60
Joined: Wed Mar 02, 2005 11:38 am
Location: Aalborg, Denmark

Post by thallish »

hi

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)

Code: Select all

echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\" name=\"chooseexperience\">";
	
	// adding userId to form
	echo "<input type=\"hidden\" name=\"userId\" value=\"$userId\" />";
	
	// following code creates HTML selection box and fills it with experience from the database 
	// that belong to the specified user
    echo "<p>Vælg en erfaring i drop-down boksen, hvis du vil opdatere ellers vælg Tilføj Ny: <br />";
    echo "<select size=\"1\" onchange=\"this.form.submit()\" name=\"technologyKeywords\" >";
        
		echo "<option value=\"none\">
						Vælg erfaring
					</option>";
		
	// connecting to database
    $connection 	= connection();
    
	$query 	= "SELECT 	experienceelement.technologyKeywords
					FROM 	user_employee,
								employee,
								competence,
								experienceelement
					WHERE 	user_employee.userId ='$userId' 
					AND 		employee.employeeId = user_employee.employeeId
					AND		employee.competenceId = competence.competenceId
					AND		competence.experienceId = experienceelement.experienceId
					";

    $result 	= mysql_query($query) or die("<p> Der opstod en fejl ved indhentning af data" . mysql_error() . "</p>");

    $row = null;
	
	while ($row = mysql_fetch_array($result)) {

            echo "<option value=\"{$row['technologyKeywords']}\">
						{$row['technologyKeywords']}
					</option>
			";
    }
        
	//closing database connection
	DBClose();
	
	echo "</select>";
    
	//echo "<input type=\"submit\" value=\"Vælg\" />";
	
	echo "</p>";
	
	echo "</form>";


	$keywords	=	$_POST['technologyKeywords'];
	
	$userId = $_SESSION['userId'];
	
	echo "<form action=\"profileeditted.php\" method=\"post\" name=\"edittechnical\">";

	// identifying form
	echo "<input type=\"hidden\" name=\"edittechnical\" />";

	// adding userId to form
	echo "<input type=\"hidden\" name=\"userId\" value=\"$userId\" />";

	//connecting to database
	$connection = connection();
		
	$query 	= "SELECT 	*
					FROM 	experienceelement,
								user_employee,
								employee,
								competence
					WHERE 	experienceelement.technologyKeywords ='$keywords'
					AND		user_employee.userId='$userId' 
					AND		employee.employeeId=user_employee.employeeId
					AND		employee.competenceId=competence.competenceId
					AND		competence.experienceId=experienceelement.experienceId
					";

	$result 	= mysql_query($query) or die("<p> Der opstod en fejl ved indhentning af data" . mysql_error() . "</p>");
		
	//preparing variables
	$experienceElementId 	=	null;
	$technologyKeywords	= 	null;
	$description 				= 	null;
	$levelOfKnowlegde 		= 	null;
	
	while($row = mysql_fetch_array($result)){
		
		$experienceElementId	=	$row['experienceElementId'];
		$technologyKeywords 	= 	$row['technologyKeywords'];
		$description				= 	$row['description'];
		$levelOfKnowlegde		= 	$row['levelOfKnowlegde'];
		
	}
		
	echo "
			<input type=\"hidden\" size=\"67\" name=\"experienceElementId\" value=\"$experienceElementId\" />
	";
		
	echo "
		<p>Keywords: <br />
			<input type=\"text\" size=\"67\" name=\"keywords\" value=\"$technologyKeywords\" />
		</p>
	";

	echo "
		<p>Beskrivelse af teknologien: <br />
			<textarea wrap=\"physical\" rows=\"7\" cols=\"50\" name=\"knowlegdeDescription\">$description</textarea>
		</p>
	";

	echo "
		<p>Vælg vidensniveau: <br />
			<select name=\"levelOfKnowlegde\">
	";
	
			echo "<option value=\"none\">Vælg niveau</option>";
	
	if($levelOfKnowlegde == '1'){
			echo"
				<option value=\"1\" selected=\"selected\">Begynder</option>
				
			";
	} else if($levelOfKnowlegde == '2'){
			echo"
				
				<option value=\"2\"selected=\"selected\">Udførende</option>
				
			";
	} else if($levelOfKnowlegde == '3'){
			echo"
				
				<option value=\"3\"selected=\"selected\">Erfaren udførende</option>
				
			";
	} else if($levelOfKnowlegde == '4'){
			echo"
				
				<option value=\"4\" selected=\"selected\">Coacher/Underviser</option>
				
			";
	} else if($levelOfKnowlegde == '5'){
			echo"
				
				<option value=\"5\" selected=\"selected\">Udvikler området</option>
			";
	}
			echo "</select>
		</p>
	";
	
	echo "
		<p>
			<input type=\"submit\" value=\"Opdater profil\" />
		</p>
	";
	
	echo "</form>";
thats my code.

hope there is an answer to my troubles :lol:

regards
thallish
Post Reply