Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:44:15+00:00 2026-05-26T06:44:15+00:00

I built a simple database where the page displays a random selection of quotes

  • 0

I built a simple database where the page displays a random selection of quotes which are displayed in an unordered list. A js script cycles through each list item showing them one at a time.

This is the query loop:

while ($row = mysql_fetch_assoc($query)) {
    echo "<li><span id='id'>";
    // print the quote number
printf ("%s", $row['id']);
    echo "</span>&nbsp;<span id='quote'>";
    // print the quote
printf ("%s", $row['strategy']);
    echo "</span>&nbsp;<span id='author'>";
    // print the quote author
    printf ("by %s", $row['author']);
    echo "</span></li>";

}

So far so good. My problem is how to show the number of likes and dislikes, and have users ‘vote’ on them. I cannot figure out how I can keep array data active once it is printed out like this. Could I use a counter to keep track of row elements in PHP so I can then know which quote the user is voting on?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:44:15+00:00Added an answer on May 26, 2026 at 6:44 am

    Your code was hard to read so I rewrote it. You want to use the quote id number to access other data about the quotes. Dhruv’s example was a good way to use an element’s id and get the data with javascript. But for some things you might want to handle more of it on the server.

    // assume the numbers I'm using are valid quote ids
    $like_array=array(12=>'15 likes', 14=>'2 likes', 18=>'6 likes');
    
    $output ='';
    
    while ($row = mysql_fetch_assoc($query)) {
        $output .= "<li><span id='id'>{$row['id']}</span>&nbsp;";                     // quote number
        $output .= "<span id='quote'>{$row['strategy']}</span>&nbsp;";                // print the quote
        $output .= "<span id='author'>by {$row['author']}</span></li>";               // print the quote author
        $output .= '<a href="http://somelink.com/page.php?like='.$row['id'].'"></a>'; // like link
        $output .= '<span>Number of likes: '.$like_array[$row['id'].'</span>';        // like link
     }
    
     echo $output;
    

    You can see that the like link is just a link that passes the quote’s id as a $_GET variable. For the number of likes part assume that we already have that information and it’s already in an array with the index keys being the quote ids. (That’s the $like_array)

    This is just the basic idea, but should get you going in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built this simple script to input a certain number, Now I want to
I building a simple, 7 page, database driven, website, and I would like to
I'm writing a simple code generation application to build POCO's from a DB2 database
I built a simple social community website for a client - the client would
I have built a simple menu in jQuery http://vanquish.websitewelcome.com/~toberua/ Here is a sample of
I've built a simple cms with an admin section. I want to create something
I've built a simple snake game that uses a Main class (this is my
I've built a simple sign in POST form that gets submitted via AJAX (default
Having read Joe Armstrong's book and watched Kevin Smith screencasts I've built a simple
I have built a pretty simple REST service in Sinatra, on Rack. It's backed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.