I had a feeling this was a for loop. Thank you! and you're right. But I still have a (numbskull - literally) problem.
Here's how I have things set up.
Author Table Fields:
author_id | first_name | last_name
Article Table Fields:
article_id | title | full_story | author_id
So, when someone submits a story the tables are linked together by the author_id field in the Article table.
Once I get the article information from the database:
$result = (SELECT * FROM articles WHERE article_id = $article_id, $db);
I then have the author_id's which (if more than one) are comma-separated, giving me data in that field that looks like 7,23,14 for example. To get at this I do the following:
$author_id = explode(",", $author_id);
foreach($author_id as $author) {
$result_author = mysql_query("SELECT * FROM authors WHERE author_id = $author", $db);
$row_count_author = mysql_num_rows($result_author);
if ($row_count_author == 0) {
echo ("");
} else {
while ($row_author = mysql_fetch_array($result_author)) {
$editor_first_name = $row_author["first_name"];
$editor_last_name = $row_author["last_name"];
$editor = $editor_first_name.' '.$editor_last_name;
echo ("$editor,");
}
}
}
So now I would see these authors (for example):
Harry Potter, Tina Turner, Bill Clinton, <-- the dreaded trailing comma!
I tried the for loop that you provided -- thanks for that! -- but I'm a little confused (and a lot tired of this code problem!) as to what your "names[]" array refers to in my code. I think with that cleared up I can get this thing working.
Thanks so much for all of your help. And apologies that I didn't post what I had coded previously.