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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:14:00+00:00 2026-06-14T21:14:00+00:00

I’m using PHP to access a MYSQL database and I’m needing to extract data

  • 0

I’m using PHP to access a MYSQL database and I’m needing to extract data from a table. The problem is that there is only one field to be fetched.

 $mysqli = new mysqli($hostname, $username, $password, $db_name);

        // Output error info if there was a connection problem
        if ($mysqli->connect_errno)
            die("Failed to connect to MySQL: ($mysqli->connect_errno) $mysqli->connect_error");

        $db = "SELECT username1 FROM Friends WHERE username2 = '"."$username"."' UNION SELECT username2 FROM Friends WHERE username1 = '"."$username"."'";

        $result = $mysqli->query($db) or
            die ("Wasn't able to search the database");

        while($result->fetch_field($row))
        {
            echo "<h1> $row </h1>";
        }

I guarantee that I am connected to my database. I also used $result->fetch_field() instead of $row in the parentheses. My main problem is that fetch_field returns an object but in all of the manuals on PHP they don’t say how you extract the actual value that the field has.

  • 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-14T21:14:01+00:00Added an answer on June 14, 2026 at 9:14 pm

    Are you sure that your variable $username in your query is what you expect it to be? Your SELECT could be returning 0 rows.

    You are using $username twice in your code.
    First in your mysqli–

    $mysqli = new mysqli($hostname, $username, $password, $db_name);
                                    --------- 
    

    And again in your SELECT –

    $db = "SELECT username1 FROM Friends WHERE username2 = '"."$username"."' UNION SELECT username2 FROM Friends WHERE username1 = '"."$username"."'";
                                                               ---------                                                               ---------
    

    Try adding

    if ($result->num_rows > 0){
      while ($row = $result->fetch_row()) {
      echo "<h1>".$row[0]."</h1>";}
    }
    else {echo "No Query / Returned 0 Rows";}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am currently running into a problem where an element is coming back from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to create an if statement in PHP that prevents a single post
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.