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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:27:54+00:00 2026-06-09T15:27:54+00:00

I have this code that I’ve been working on and when I run it

  • 0

I have this code that I’ve been working on and when I run it I get the first result 10 times (it used to repeat infinitely until I added the if statement). It’s supposed to return the first 10 results. I’ve looked at a couple other similar questions but none of the solutions on those worked here. Can anyone see what I’m missing?

<?php
$link = mysql_connect('XXXXXXXXX.com', 'XXXXXX', 'XXXXX');
$db = mysql_select_db('a1007515_troop1', $link);
$i = 1;
while($row = mysql_fetch_array(mysql_query('SELECT * FROM `posts` ORDER BY `pid` DESC LIMIT 10;')))
{
$authinfo = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = '.$row['aid'].' LIMIT 1'));
echo '
<div class="content">
<a href="post.007?pid='.$row['pid'].'"><h1 class="title">'.$row['title'].'</h1></a>
<span class="authinfo">This post was made by '.$authinfo['name'].'<i>('.$authinfo['username'].')</i> on '.$row['date'].'.</span>
<p class="txt">'.$row['content'].'</p>
</div>';
if ($i == 10) { break; }
++ $i;
}
mysql_close($link);
?>
  • 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-09T15:27:56+00:00Added an answer on June 9, 2026 at 3:27 pm

    Maybe try simplifying things, try and stick to doing one thing per line, rather than trying to compress it.

    Calling mysql_query in the while will repeat that query every time the while loop is run, rather than fetch the next result. Running another mysql query while iterating through the results of another one can also cause problems.

    $link = mysql_connect('mysqlwebhost', 'user', 'pass');
    $db = mysql_select_db('dbname', $link);
    
    $result = mysql_query('SELECT * FROM `posts` p, `users` u WHERE u.id = p.aid  ORDER BY `pid` DESC LIMIT 0,10;');
    
    while ($row = mysql_fetch_assoc($result)) {
        echo '
        <div class="content">
        <a href="post.007?pid='.$row['pid'].'"><h1 class="title">'.$row['title'].'</h1></a>
        <span class="authinfo">This post was made by '.$row['name'].'<i>('.$row['username'].')</i> on '.$row['date'].'.</span>
        <p class="txt">'.$row['content'].'</p>
        </div>';
    }
    
    mysql_close($link);
    

    You may also wish to avoid using mysql_* functions as they have been deprecated. Have a look at either mysqli or PDO.

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

Sidebar

Related Questions

I have this code that extracts the first image from an article in joomla:
I have this code that I want to a) run when the check box
I have this code that I run when a user submits a form (this
I have this code that edits addresses in a game to get unlimited ammo
I have this code that will grab the names, but how do i get
I have this code that we can write in two ways First Way void
I have this code that's working only on Firefox and not all browsers, although
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static
I have this code that reads from XML file. It gets five strings (groupId,

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.