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 7764175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:50:38+00:00 2026-06-01T14:50:38+00:00

Hello i’m trying to make a tag script for my website so each time

  • 0

Hello i’m trying to make a tag script for my website so each time a search engine comes to my website 10 different tags will show on my website.

These tags will be grabbed from the db.
So at the minute i have coded it so it grabs only one. ( because i don’t know how to do a while )

Like so

$sql = "SELECT tagname FROM tags ORDER BY rand() LIMIT 10";
$result = mysql_query($sql);
$row = mysql_fetch_object($result);
echo "<a href='index.php'>" .$row->tagname. " </a>";

Is there anyway i can add a while to that so it does it 10 times ? E.g use the same echo but print out 10 results instead of the 1 …. i have changed the limit from 1 to 10 but that did not work… still showing one…

  • 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-06-01T14:50:40+00:00Added an answer on June 1, 2026 at 2:50 pm

    Note, read before the real answer: for the ones that keep downvoting this answer. Read the title (that starts with “Doing a while“) and the final part, the question (“Is there anyway i can add a while to that so it does it 10 times ?”). This answer is about iterating the result set, not about the usage of the RAND function! The query doesn’t even appear in my answer, and I am also suggesting a different approach at the end:


    you just need to wrap your call to mysql_fetch_object in a loop

    $result = mysql_query($sql);
    
    while ($row = mysql_fetch_object($result))
    {
    echo "<a href='index.php'>" .$row->tagname. " </a>";
    }
    

    Later edit
    Other considerations would be:

    • if the table hold a very big amount of data (but it doesn’t seem that it will) order by rand() can have a bad effect on the performance
    • consider using pdo (or at least mysqli)
    • you should have some error handling even if the query seems to be
      perfect, at least

      if (!$result)
      {
      echo mysql_error();
      die;
      }

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

Sidebar

Related Questions

Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello I am trying to save a bitmap image in a basic image editor
Hello everyone i am trying to format the input number range with php number_format
hello friends i am trying to get a list of user id and want
Hello Guys I am trying to figure out why i am gettings this error
Hello fellow developers... just to make sure, I want to ask this question: How
Hello All I am trying to flatten a list in Ocaml. I am a
Hello I was writing a Regular Expression (first time in my life I might
Hello I am compiling a program with make but I get the error of
Hello , I am currently working on the student association's website. The student's association

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.