Current location: Hot Scripts Forums » Programming Languages » PHP » Pull down menu populated by database info - displaying selected option


Pull down menu populated by database info - displaying selected option

Reply
  #1 (permalink)  
Old 06-24-09, 05:34 PM
bluedogsb bluedogsb is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Pull down menu populated by database info - displaying selected option

So I have an html pull down menu populated by database information that is specific to a registered user. This makes it so only the user can choose his/her projects and no one else's. The trick is displaying the chosen project's information from the database on the same page. So basically if the user chooses a project from the menu, I need it to display that project and only that project.

The form code:
Code:
<form>
			<?
			include("mysqlconnect.php");
			
			$user = $session->username;
			$sql="SELECT projname FROM projects WHERE assignto = '$user' ";
			$result=mysql_query($sql);
			$options="";
				
				while ($row=mysql_fetch_array($result)) {
					$project=$row["projname"];
    				$options.="<OPTION VALUE=\"$project\">".$project.'</option>';
				}
				
			
			?>
			<select name="projname">
			<option>Choose Project
			<?=$options?>
			</option>
			</select>
			<input type="submit" value="Track Project">
			</form>
I realize I have no action in the form, but this is where you guys come in. I understand processing a form, but I can't get it to render on the same page. Email forms were easy, registration forms were easy but just saved the info. Can anyone do a quick help idea to help me render the data on the same page?
Reply With Quote
  #2 (permalink)  
Old 06-25-09, 12:50 PM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
well depands on whtat you want to do, if you want it to showup on the same page with out the page having to refresh, you could look into AJAX, otherwise just have your form submit back to itsefl using $_SERVER['PHP_SELF'] then at the top of your code just check to see if your form was submitted or not and it it was do your DB calls and get your info needed and display

so your code flow would look something line

PHP Code:

<?

if($_GET['projname'] != "")
{
    
//get project info
    
$content display_project();
}
else
{
    
$content display_startpage();
}
?>

<html>
<body>
normal header code and project selector....
<?= $content ?>
normal footer stuff
</body>
</html>

hope it helps
Reply With Quote
  #3 (permalink)  
Old 06-26-09, 04:11 PM
bluedogsb bluedogsb is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
I can't seem to get it to work for some reason, although different things have happened as I messed around with it. Is there a more specific explanation?
Reply With Quote
  #4 (permalink)  
Old 06-26-09, 05:25 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
What you are asking is really vague.

A simple answer to a vague question would be, use if/else statements.

PHP Code:


if(isset($_POST['projname']))
{

//Print this to the page... Everything that you want to show after the user chooses an option.

} else {

//Print the form, and dropdown options...


PS. It is bad practice to use short tags, as most servers have them turned off. Besides it is not hard to type that extra PHP...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic option menu nicpon PHP 3 09-12-05 03:24 PM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM
using JS to pull information from database flososic JavaScript 5 06-19-05 05:48 PM
Remember "selected" option on dropdown menu dihan PHP 4 04-28-05 12:07 PM
Drop Down Menu populated by Database maweber98 PHP 5 08-20-04 10:43 AM


All times are GMT -5. The time now is 08:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.