Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lists from DB

Status
Not open for further replies.

manicleek

Technical User
Jun 16, 2004
143
GB
I have a page to edit an article in a db.

When the article is initially added there is a multiple selection list box with records listed.

The user can select a number of records which is then submitted to the db with each record selected on a new line in a mediumtext field.

On the edit page I am trying to list all the records in the list box again but with the records that were added initially already selected.

I already have it sort of working using the following code:


Code:
<select name="internal[]" size="15" multiple="multiple" id="internal[]"> 
<? 
while ($internalRS = mysql_fetch_array($internalresults)) { 

foreach(explode("\n", $editRS['internallinks']) as $intlinks) 
    { 
    $intlistSQL = "SELECT articleid, articletitle FROM mainarticle WHERE articleid = '" . $intlinks . "'"; 
    $intlistresults = mysql_query($intlistSQL); 
    $intlistRS = mysql_fetch_array($intlistresults); 
?> 
<option value="<?= $internalRS['articleid'] ?>" <? if ($intlistRS['articleid'] == $internalRS['articleid']) { ?>selected="selected"<? } ?>> 
<?= $internalRS['articletitle'] ?> - <?= $internalRS['maincatname'] ?> - <?= $internalRS['subcatname'] ?> 
</option> 
<? } } ?> 
</select>

However, using this code it lists each article twice
 
Can you show me what is the output for this?
And also, you have:

foreach(explode("\n", $editRS['internallinks']) as $intlinks)

This can cause the duplication in listing.
However, please let me know your current output, and the expected output.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top