Dear all,
In my work I have to get some values from database and display them in a multiple select item. After the user chooses some items and clicks submit button, I have to display selected and unselected items in the next page. For this I wrote a code as follows. The problem with this code is: I am able to get the selected items only but I need the complete list of all items in that multiple choice box. Hence I request all of you to tell me a possible way to solve this problem. I am sending herewith the table structure and code that I used to process my work.
Table-Structure: - create table nuke_user_articles(article_id int(6) primary key auto_increment,
article_name varchar(200));
Values in the table: - insert into nuke_user_articles values('','Beyond commerce: Bringing business relationships and community to the web');
insert into nuke_user_articles values('','Where do the Objects Come From?');
insert into nuke_user_articles values('','Calling Down the Lightning');
insert into nuke_user_articles values('','Apprenticing with the Customer');
insert into nuke_user_articles values('','Making Customer-Centered Design Work for Teams');
1)mselection1.php
<?php
$user = "user";
$pass = "pwd";
$db = "mydb";
$link =mysql_connect("localhost",$user,$pass);
if(!$link)
die("Could not connect MySQL");
mysql_select_db($db,$link)
or die("Could not open $db: ".mysql_error());
?>
<html>
<body>
<FORM name="Register" action="mseltest1.php" method="post">
<p align="center"><select size=3 multiple name="monChoice[]">
<?php
$r = mysql_query("select article_id, article_name from nuke_user_articles");
while($row = mysql_fetch_array($r))
{
echo '<option value='.$row['article_id'];
echo '>'.$row['article_name'].'</option>';
}
?>
</select></p><BR>
<input type="submit" value="Submit" name="B1"></p>
</FORM>
</body>
</html>
2) mseltest1.php
<?php
$user = "root";
$pass = "root";
$db = "infv_Phyzone2";
$link =mysql_connect("localhost",$user,$pass);
if(!$link)
die("Could not connect MySQL");
mysql_select_db($db,$link)
or die("Could not open $db: ".mysql_error());
?>
<html>
<body>
echo"<p align=\"center\"><select size=\"3\" multiple name=\"monChoice[]\">";
<?php
foreach($monChoice as $value)
{
$qryselect="select article_id,article_name from nuke_user_articles where article_id=$value";
$arlistnames = $dbconn->Execute($qryselect);
list($atid,$aname) = $arlistnames->fields;
echo "<option selected value=$atid>$aname\n";
}
?>
</body>
</html>
Regards,
Seenu.