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

  • Home
  • SEARCH
  • 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 6144267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:37:34+00:00 2026-05-23T18:37:34+00:00

First, I coded this, which looks inside a table, gets the last 10 entries,

  • 0

First, I coded this, which looks inside a table, gets the last 10 entries, and displays them. The output is as expected, a list of the 10 last entries in the database.

$query = "SELECT dfid FROM downloads_downloads ORDER BY did DESC limit 10"; 
$dlresult = mysql_query( $query );
$i=0;
$num = mysql_num_rows ($dlresult);

     while ($i < $num) {
          $dfid= mysql_result($dlresult,$i,"dfid");

          echo "<b>filenumber:</b> $dfid <br>";

          ++$i; 
                  }

But I don’t just need the filenumber. I need the actual filename and url from another table. So I added a select statement inside the while statement, using the file number.

But for some reason, this code only displays one filename instead of 10. I know, from the above code, it’s getting all 10 file numbers.

$query = "SELECT dfid FROM downloads_downloads ORDER BY did DESC limit 10"; 
$dlresult = mysql_query( $query );
$i=0;
$num = mysql_num_rows ($dlresult);

     while ($i < $num) {
         $dfid= mysql_result($dlresult,$i,"dfid");
         $query2 = "SELECT file_name, file_name_furl FROM downloads_files WHERE file_id = '$dfid'";
         $dlresult2 = mysql_query( $query2 );
         $dlfile_name= mysql_result($dlresult2,$i,"file_name");
         $dlfile_name_furl= mysql_result($dlresult2,$i,"file_name_furl");

         echo "filenumber: $dfid <br>"; //Shows 10, as expected.
         echo "filename: $dlfile_name - $dlfile_name_furl <br>"; //Shows only 1?

         ++$i; 
                  }

I can manually execute the sql statement and retrieve the file_name and file_name_furl from the table. So the data is right. PHP isn’t liking the select within the while statement?

  • 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-23T18:37:34+00:00Added an answer on May 23, 2026 at 6:37 pm

    Looks like you’re only going to ever have 1 row, in your 2nd select statement, because you are just selecting one row, with your where statement.

    So, you’re only going to ever have row 0 in the 2nd statement, so its only finding row 0 on the first loop. try instead:

    $dlfile_name= mysql_result($dlresult2,0,"file_name");
    $dlfile_name_furl= mysql_result($dlresult2,0,"file_name_furl");
    

    However, insrtead of making 11 separate queries, try using just one:

    $link = new mysqli(1,2,3,4);
    
    $query = "SELECT downloads_downloads.dfid, downloads_files.file_name, downloads_files.file_name_furl FROM downloads_downloads LEFT OUTER JOIN downloads_files ON downloads_files.file_id = downloads_downloads.dfid ORDER BY downloads_downloads.dfid DESC limit 10;
    
    $result = $link->query($query) ;
    if((isset($result->num_rows)) && ($result->num_rows != '')) {
    while ($row = $result->fetch_assoc()) {
        echo "filenumber: $row['dfid'] <br>"; 
        echo "filename: $row['file_name'] - $row['file_name_furl'] <br>"; 
    }
    

    Read up on mysql joins http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.php

    I’m not sure if this is syntax correct, but it gives you the right idea =)

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

Sidebar

Related Questions

Code first: '''this is main structure of my program''' from twisted.web import http from
First check out this code. I seems like it should work for me, but
I have this code: tableList = [[NSMutableArray alloc] initWithObjects:@First View,@Second View,nil]; I have synthesized
when I run this code for the first time <?php session_start(); echo SID; ?>
I use this code to determine checkbox width and height: var chk = $('input[type=checkbox]:first');
I have been using this code with great success to pull out the first
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
Can anyone explain why this code with the given routes returns the first route?
I got this code ` // // prints out Hello World! // hello_world(); //First
I've got this code snippet, and I'm wondering why the results of the first

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.