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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:55:58+00:00 2026-06-02T04:55:58+00:00

So I do this to retrieve my entire table: $result = mysql_query( ‘SELECT *

  • 0

So I do this to retrieve my entire table:

$result = mysql_query( 'SELECT * FROM mytable' );

Then, in another part of my PHP-page, I do another query (for a specific row):

$result2 = mysql_query( 'SELECT * FROM mytable WHERE id = ' . $id );
$row = mysql_fetch_array( $result2 );

So, I’m performing two querys. However, I don’t really have to do that, do I? I mean, the row that I’m retrieving in my second query already is present in $result (the result of my first query), since it contains my entire table.

Therefore, instead of doing the second query, I would like to extract the desired row from $result directly (while keeping $result itself in tact).

How would I do that?


OK, so this is how I’ve implemented it:

function getRowById ( $result, $id )
{
    while ( $row = mysql_fetch_array( $result ) ) {
        if ( $row['id'] == $id ) {
            mysql_data_seek( $result, 0 );
            return $row;
        }
    }
}
  • 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-02T04:55:59+00:00Added an answer on June 2, 2026 at 4:55 am

    You can loop through the result set to find the row, and then reset the internal pointer back to the first row:

    while($row = mysql_fetch_array( $result))
    {
      if($row['id'] == $id)
      {
        //row found, do processing ...
        //reset pointer and break from loop
        if(!mysql_data_seek($result, 0))
          //handle error
        break;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making this method retrieve records from the Data Base. As you can see
this is my xml file,i do not known how to retrieve value from xml
PHP lists this example as a way to retrieve database data. <?php $return =
I know this will let the user retrieve the latest 10 posts from cocacola
I'm trying to retrieve a variable from an extended class. This is how my
I have a php page which shows an entire time schedule for a user
How can I retrieve a text field from mysql db table, but not the
Simply this the code for PHP page the uses AJAX to upload file, but
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I've this LINQ to XML request which retrieve all songs by artist ID :

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.