开发者

update with combo box

I have job insert page which is working fine. I just build an update page in admin panel. I'm not able to show screen short :(

I need to show the category as selected which is already in the job table.

let me show you the table details.This is the job table

    CREATE TABLE IF NOT EXISTS `jobs` (
  `job_id` int(11) NOT NULL AUTO_INCREMENT,
  `job_title` varchar(99) NOT NULL,
  `job_category` int(3) NOT NULL,
  `job_location` varchar(33) NOT NULL,
  `job_country` varchar(33) NOT NULL,
  `job_salary` int(12) NOT NULL,
  `job_reference` varchar(9) NOT NULL,
  `job_contact_name` varchar(9) NOT NULL,
  `job_description` text NOT NULL,
  `job_requirments` text NOT NULL,
  `job_companydetails` text NOT NULL,
  `status` int(2) NOT NULL,
  `date` date NOT NULL,
  `featured` int(1) NOT NULL,
  PRIMARY KEY (`job_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1091 ;

and this is the category table

CREATE TABLE IF NOT EXISTS `job_categor开发者_StackOverflow中文版y` (
  `category_id` int(11) NOT NULL AUTO_INCREMENT,
  `category_name` varchar(25) NOT NULL,
  PRIMARY KEY (`category_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

I'm just showing data from job table for update. but the thing is that I need to show JOB CATEGORY in the Combobox. I think it is easy through like this

<select name="job_category">
<?php
$result = mysql_query("SELECT * FROM $category_tbl");
while($row = mysql_fetch_array($result))
{       
echo "<option value=$row[category_id]> $row[category_name] </option>";
}
?>
</select>

but the thing is that I need to show selected category name which is in the job table


In the while loop you can have something like:

 while($row = mysql_fetch_array($result)) { 
      echo "<option value='$row[category_id]'";
      if($row['category_id'] === $rows['job_category']){
           echo "selected='selected'";
      }
      echo "> $row[category_name] </option>";
 } 

job['job_category'] would contain the category id of the job you are currently displaying.

Hope this helps.


It is has some bug I just fixed it look the changes

$result = mysql_query("SELECT * FROM $category_tbl");
    while($row = mysql_fetch_array($result)) 
    { 
  echo "<option value='$row[category_id]'";
  if($row['category_id'] === $rows['job_category'])
      {
       echo "selected='selected'";
  }
  echo "> $row[category_name] </option>";
     } 

thanks for your clue

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜