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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:48:51+00:00 2026-05-30T07:48:51+00:00

I am trying to access the $Frined_Id outside the while loop. But it is

  • 0

I am trying to access the $Frined_Id outside the while loop. But it is only returning the last accessed element. Is there any method so that i can store the value of Friend Id inside the array and then can use them in program whenever i want.

$query="SELECT * FROM `user_friend` WHERE `User_Id`='$id'";
if($query_run=mysql_query($query))
    {
    $mysql_num_rows=mysql_num_rows($query_run);
    $i=$mysql_num_rows;
    while($row=mysql_fetch_array($query_run))
        {
            $Friend_Id=$row['Friend_Id'];
            $Name=$row['Friend_Name'];
            $Name_array=array("$Name");
            echo "<a href=\"view_profile.php?id=$Friend_Id\"/>".$Name."</a>".'<br>';

        }
        echo $Friend_Id;
} 
  • 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-30T07:48:52+00:00Added an answer on May 30, 2026 at 7:48 am

    The reason it only shows the last one is because it gets changed each time in the loop and the last thing it was set to is what it is. A fix for being able to access all of them is make $Friend_Id an array as such:

    $Friend_Id[] = $row['Friend_Id'];
    

    Then after your loop, you can access them by index

    // Show the first one
    echo("Friend ID is " . $Friend_Id[0]);
    
    // Show the third one
    echo("Friend ID is " . $Friend_Id[2]);
    

    You can make it even more useful by making an associative array containing the name and id like:

    $friend[] = Array($Name => $Friend_Id);
    

    Just a few ideas…

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

Sidebar

Related Questions

I'm trying to access a method in a class I made, but since it
After trying to access ivars using KVC, I have noticed that there was no
Trying to access a Servlet from a button on HTML page //Html Page FORM
Am trying to access an API using CURL I can access the API from
Im trying to access a web service from a remote computer. I managed to
Im trying to access the Magento customer session in another part of my website.
Im trying to access a Sql CE 2005 database on a windows mobile device
I'm trying to access the .html files and extract the text in <p> tags.
I'm trying to access a samba share that requires authentication. I do not want
I have been trying to access an HTTPS URL with the HTMLUnitDriver API of

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.