Jump to content

Recommended Posts

Alright this is kinda an odd thing, so I need some help.

 

I have a table "quote" with the three columns `id`, `quote`, and `author`.

 

Now I am wondering if there is anyway that I can output all the different values in the column `author`, and if a repeat is found, not to display it again.

 

I know I can do this in a for loop, but I know there is a better way to do it. Always is.

 

Any help or suggestions are always greatly appreciated.

 

Thanks in advanced.

--nonexistentera

It would help if you told us more about your problem and gave us more specifics, like where do you want to use it? If it's SQL then CV's solution will do but you will get one quote per author (last or first, not sure)

 

If you want to create this in HTML using PHP then it would be something like:

$result = mysql_query('SELECT * FROM quote ORDER BY author');// it's important to sort by author or the author's name will be duplicated across the page

$author = "";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if (0 === strcasecmp($author, $row['author'])) {
        echo '<h2>', $row['author'], '</h2>';
        $author = $row['author'];
    }
    echo '<p>', $row['quote'], '</p>';
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.