View Single Post
Old 02-17-2008, 04:07 AM   #1 (permalink)
sarmenhb
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default dynamic dropdown not working

heres the function im using

when i load the page the drop down doesnt show anything. so im wondering if there is a syntax error u can find because my ide isnt finding any.

this is how im typing the html out

<select><?php dyn_dropdown(tbl_status,status); ?></select>



Code:
function dyn_dropdown($tablename,$columnname) {


	$query = mysql_query("SELECT $columnname FROM $tablename");
	
	if(mysql_num_rows($query))
	{
	while($row = mysql_fetch_assoc($query))
	{
	$block = "<option>";
	$block .=  $row['$columnname'];
	$block .= "</option>";

	}
	
	}
	else {
	echo "<option>no data</option>";
	}

}


here is the table structure

tbl_status

Code:
CREATE TABLE `tbl_status` (
  `id`      int AUTO_INCREMENT NOT NULL,
  `status`  varchar(20) NOT NULL,
  /* Keys */
  PRIMARY KEY (`id`)
) ENGINE = InnoDB;
heres the data it contains

Code:
        id status                                                       
        20 open                                                         
        21 op
__________________
no signature set

Last edited by sarmenhb : 02-17-2008 at 04:37 AM.
sarmenhb is offline  
Reply With Quote