Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Dropdown list from DB

    Code:
    <style type="text/css">
    <!--
    .style1 {
    	color: #FF6600;
    	font-family: Verdana;
    	font-weight: bold;
    }
    .style2 {font-family: Verdana}
    -->
    </style>
    </head>
    
    <body>
    
    <?
    include("db.php");
    
    			$link = @mysql_connect("localhost", $dbusername, $dbpassword);	
    
    			if (!$link)
    
    				die ("Couldn't connect to MySQL");
    
    				mysql_select_db($dbname, $link)
    
    				or die ("Couldn't open $db".mysql_error());
    				
    				
    		 $orgSelect = "Select clientName From client Order By clientName ASC";
    			
    		 $orgSelected = mysql_query($orgSelect, $link)
    		or die ("Couldn't execute orgSelect query");
    					
    		while ($row = mysql_fetch_array($orgSelected))
    		{
    		$orgoption = $row["clientName"]; 
    	
    		$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    		}
    		
    		    $tableSelect = "Select member, nonmember, nimember From forzanim_imsdb";
    						
    			$tableSelected = mysql_query($tableSelect, $link)
    			or die ("Couldn't execute tableSelect query");
    							
    			while ($row = mysql_fetch_array($tableSelected))
    			{
    				$tableOption = $row[""]; 
    			
    				$tableOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    			}	
    ?>		
    	<form method="POST" action="searchresults.php"> 
    	 <table width="430" border="0">                                                                                                                                                                                                                       "> 
    	   <tr> 
    	     <td width="363"><span class="style1"><u>Search</u></span></td> 	     
    	   </tr> 
    	   <tr>
    	     <td><span class="style2">Organisation:</span><span class="style4">
             <select name="clist" id="clientlsit">
    		 <?php echo "$clientOp";?>
             </select>
             </span></td>
           </tr>
    	   <tr> 
    	     <td class="style2">Member Type: 
    	       <select name="typetable" id="mtypetable">
    			<? echo "$tableOp";?>
                 </select></td> 
    	     
    	   </tr>
    	   <tr><td colspan='2' align='center'><input type="SUBMIT" name='submit' value="Search"> <input type="reset" name="Reset" value="Reset"></td> 
    	   </tr>
    	 </table> 
    	 </form>  	 
    </body>
    </html>
    i can't seem to populate the dropdown list from database.

    Wanna retrieve clientName from client table, and the member, nonmember and nimember table from db.

    i'm getting "Couldn't execute tableSelect query" error.

    someone please help see if anything wrong with the codes.
    Last edited by cheryl; 02-15-2006 at 02:25 PM.
    [=cHeRyL=]

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have some bad coding in there, but the main reason is because you are saving the loop into a variable but not echoing it.

    Code:
    while ($row = mysql_fetch_array($orgSelected))
    		{
    		$orgoption = $row["clientName"]; 
    	
    		$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    		}		
    		 ?>
    PHP Code:
    while ($row mysql_fetch_array($orgSelected))
            {
            
    $orgoption $row["clientName"]; 
        
            
    $clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
            }
    echo 
    $clientOp
    ?>

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Code:
    <style type="text/css">
    <!--
    .style1 {
    	color: #FF6600;
    	font-family: Verdana;
    	font-weight: bold;
    }
    .style2 {font-family: Verdana}
    -->
    </style>
    </head>
    
    <body>
    
    <?
    include("db.php");
    
    			$link = @mysql_connect("localhost", $dbusername, $dbpassword);	
    
    			if (!$link)
    
    				die ("Couldn't connect to MySQL");
    
    				mysql_select_db($dbname, $link)
    
    				or die ("Couldn't open $db".mysql_error());
    				
    				
    		 $orgSelect = "Select clientName From client Order By clientName ASC";
    			
    		 $orgSelected = mysql_query($orgSelect, $link)
    		
    		or die ("Couldn't execute orgSelect query");
    					
    		while ($row = mysql_fetch_array($orgSelected))
    		{
    		$orgoption = $row["clientName"]; 
    	
    		$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    		}
    		echo $clientOp;
    		
    		    $tableSelect = "Select member, nonmember, nimember From forzanim_imsdb";
    						
    			$tableSelected = mysql_query($tableSelect, $link)
    			or die ("Couldn't execute tableSelect query");
    							
    			while ($row = mysql_fetch_array($tableSelected))
    			{
    				$tableOption = $row[""]; 
    			
    				$tableOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    			}	
    			echo $tableOp;
    ?>		
    	<form method="POST" action="searchresults.php"> 
    	 <table width="430" border="0">                                                                                                                                                                                                                       "> 
    	   <tr> 
    	     <td width="363"><span class="style1"><u>Search</u></span></td> 	     
    	   </tr> 
    	   <tr>
    	     <td><span class="style2">Organisation:</span><span class="style4">
             <select name="clientlist" id="clientlist">
    		 <?php echo "$clientOp";?>
             
    		 </select>
             </span></td>
           </tr>
    	   <tr> 
    	     <td class="style2">Member Type: 
    	       <select name="typetable" id="typetable">
    			<? echo "$tableOp";?>
                 
    			 </select>
    		</td> 
    	     
    	   </tr>
    	   <tr><td colspan='2' align='center'><input type="SUBMIT" name='submit' value="Search"> <input type="reset" name="Reset" value="Reset"></td> 
    	   </tr>
    	 </table> 
    	 </form>  	 
    </body>
    </html>
    i think there's still something wrong with it.

    how can i select TABLES from the db??
    [=cHeRyL=]

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Umm this is what I think

    PHP Code:
    while ($row mysql_fetch_array($orgSelected))
    {
        
    $orgoption $row["clientName"]; // I dont see anywhere this variable is used

        
    $name $row['clientName'];

        
    $clientOp .= "<OPTION value=".$name.">".$name."</OPTION>";
    }
    echo 
    $clientOp//This isn't needed, he echos the whole thing further down 
    because he is using the .= operator it just keeps adding an option to the string, which should work perfectly.

  • #5
    New Coder
    Join Date
    Feb 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    it still doesn't work. I got a Couldn't execute tableSelect query.

    could someone see what is wrong with it?

    Code:
    <style type="text/css">
    <!--
    .style1 {
    	color: #FF6600;
    	font-family: Verdana;
    	font-weight: bold;
    }
    .style2 {font-family: Verdana}
    -->
    </style>
    </head>
    
    <body>
    
    <?
    include("db.php");
    
    			$link = @mysql_connect($dbhost, $dbusername, $dbpassword);	
    
    			if (!$link)
    
    				die ("Couldn't connect to MySQL");
    
    				mysql_select_db($dbname, $link)
    
    				or die ("Couldn't open $dbname".mysql_error());
    				
    		//$clientName = 'clilentName';
    		//$tableType = 'tableType';
    		
    				
    		 $orgSelect = "Select clientName From client Order By clientName ASC";
    			
    		 $orgSelected = mysql_query($orgSelect, $link)
    		
    		or die ("Couldn't execute orgSelect query");
    					
    		while ($row = mysql_fetch_array($orgSelected))
    		{
    		$clientName = $row['clientName']; 
    	
    		$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    		}
    		
    		
    		    $tableSelect = "Select member, nonmember, nimember From forzanim_imsdb";
    						
    			$tableSelected = mysql_query($tableSelect, $link)
    			
    			or die ("Couldn't execute tableSelect query");
    							
    			while ($row = mysql_fetch_array($tableSelected))
    			{
    				$tableType = $row['tableType']; 
    			
    				$tableOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
    			}	
    			
    ?>		
    	<form method="POST" action="searchresults.php"> 
    	 <table width="430" border="0">                                                                                                                                                                                                                       "> 
    	   <tr> 
    	     <td width="363"><span class="style1"><u>Search</u></span></td> 	     
    	   </tr> 
    	   <tr>
    	     <td><span class="style2">Organisation:</span><span class="style4">
             <select name="clientlist" id="clientlist">
    		 
    		 <?php echo "$clientOp";?>
             
    		 </select>
             </span></td>
           </tr>
    	   <tr> 
    	     <td><span class="style2">Member Type: 
    	       </span>
    	       <select name="typetable" id="typetable">
    		    
    			 <? echo "$tableOp";?>
                   
    	     </select>		
    		 </td> 
    	     
    	   </tr>
    	   <tr><td colspan='2' align='center'><input type="SUBMIT" name='submit' value="Search"> <input type="reset" name="Reset" value="Reset"></td> 
    	   </tr>
    	 </table> 
    	 </form>  	 
    </body>
    </html>
    i need to be able to get the client(organisation) & table type (member, nonmember &nimember) dropdown list before i can continue to write queries to select the data.

    would appreciate there are people who can help. thanks.
    Last edited by cheryl; 02-16-2006 at 01:11 AM.
    [=cHeRyL=]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •