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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:01:34+00:00 2026-06-09T03:01:34+00:00

<?php mysql_connect(localhost,root,); mysql_select_db(‘db2012’); $uid = 8; $mid = 10; $q = mysql_query(select friend from

  • 0
<?php
    mysql_connect("localhost","root","");
    mysql_select_db('db2012');
    $uid = 8;
    $mid = 10;

    $q = mysql_query("select friend from users_friends where user = $uid") or die(mysql_error());
    if(mysql_num_rows($q) > 0)
    {

        while($r=mysql_fetch_array($q))
        {
            $qq = mysql_query("select friend from users_friends where user = $mid") or die(mysql_error());
            while($rr = mysql_fetch_array($qq))
            {
                if($r[friend]==$rr[friend])
                {
                    $friend_name_query = mysql_query("select name from users where uid = '$rr[friend]'") or die();
                    $friend_name = mysql_fetch_array($friend_name_query);
                    echo $friend_name[name];
                }
            }
        }   
    }


?>

This query is working but any other way out to use less queries ? i m a beginner programmer please let me know if there is n e thng …

  • 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-09T03:01:35+00:00Added an answer on June 9, 2026 at 3:01 am

    You should use just one query:

    $query = 'SELECT u.name
        FROM users_friends f1 
          INNER JOIN users_friends f2 ON (f2.friend = f1.friend)
          INNER JOIN user u ON (u.uid = f2.friend)
        WHERE f1.user = "'. $uid. '"
          AND f2.user = "'. $mid .'"';
    

    run the query

    $q = mysql_query($query) or die(mysql_error());
    

    and do the while loop

    while($r=mysql_fetch_array($q)){
      echo $r['name'];
    }
    

    You only need the if(mysql_num_rows($q) > 0) statement if you do an else, otherwise you can just use the while

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

Sidebar

Related Questions

<?php $con= mysql_connect(localhost,root,mysql); mysql_select_db(Db_name,$con); $res=mysql_query(select *from table_name); mysql_close($con); // closing connection before fetching contents.
I am calculating one parameter(X) this way: <?php $link=mysql_connect(localhost,root,); mysql_select_db(hand); $result = mysql_query(select *
<?php ini_set('display_errors', 0); $search = $_GET ['search']; mysql_connect(localhost, root, gokul); mysql_select_db(search123); $query = mysql_query(SELECT
Ok so i have a php script: <?php mysql_connect(localhost,root,root); mysql_select_db(FYP); $sql=mysql_query(select team_name, games_played, games_won,
<?php $con = mysql_connect(localhost,root,); mysql_select_db(image, $con); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $result = mysql_query(SELECT
<?php $objConnect = mysql_connect(localhost,,root) or die(mysql_error()); $objDB = mysql_select_db(mydb); $pic2 = SELECT * FROM
code: sql.php <?php $uid = trim($_POST['uid']); $pass= trim($_POST['pass']); $type= trim($_POST['type']); $link = mysql_connect(localhost,root,akash); if
Here is the code that I'm working on: login.php: <?php $con = mysql_connect(localhost,root,); mysql_select_db(koro,$con);
Probably problem with the php file which contains the following code: <?php mysql_connect(localhost,root,); mysql_select_db(deal);
Consider the following code: <?php $conn = mysql_connect('localhost', 'username', 'password'); mysql_select_db('database', $conn); ?> This

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.