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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:26:29+00:00 2026-05-16T18:26:29+00:00

In PHP I am having difficulty trying to extract row data from one SQL

  • 0

In PHP I am having difficulty trying to extract row data from one SQL Query results. The service information I require is stored in an array called $SelectedItems. The Code below works as it should but Prints the Entire table with all rows. How would I get it to simply print the 1 row.

    $sql ="select blah blah"
    //Output result
    $result = mysql_query($sql);


    //Generate Information about Service or Product
    while($row = mysql_fetch_array($result))
      {
        if (in_array($row['Service_Name'], $SelectedItems)){
            print $row['Service_Description'];
            print $row['Service_Cost'];
        }
      };

I am pretty new to PHP and might be going about this in the wrong way please let me know if im being back to front lol.

The $SelectedItems are processed from $_POST Data and the required data is set into an array

//Finds Out which services have been selected
foreach (array_keys($_POST) as $key) {
$$key = $_POST[$key];
    if ($$key == "1"){
        print "$key is ${$key}<br />";
        $SelectedItems[] = $key;
    };
};
  • 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-16T18:26:30+00:00Added an answer on May 16, 2026 at 6:26 pm

    I see no faults in this code at glance (however I don’t have an PHP interpreter in my head, thus I can’t tell for sure).

    Anyway, you have to start to debug your code with actual data.
    Why not to output both $row['Service_Name'] and $SelectedItems? Better by using var_dump() function.
    It can be type casting issue or or missing data or anything. Watching the actual data with your own eyes always helps

    Just side note on your second loop. It’s odd and dangerous.
    And should be just

    foreach ($_POST as $key => $value) {
        if ($value == "1"){
            print "$key is $value<br />";
            $SelectedItems[] = $key;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I havent use Propel outside of Symfony but from what… May 17, 2026 at 1:56 am
  • Editorial Team
    Editorial Team added an answer Personally, I'd recommend writing a function rather than an alias… May 17, 2026 at 1:56 am
  • Editorial Team
    Editorial Team added an answer You can find plenty of information about log4net and NLog… May 17, 2026 at 1:55 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to create an authentication mechanism for my PHP Application and I'm having
I'm building a small scale forum script in PHP, and I am having difficulty
I have a rather complex logical query I'm trying to execute. Essentially there are
I'm trying to port a PHP site developed by another coder (who is no
I'm having a lot of difficulty matching an image url with spaces. I need
I'm trying to build an active page menu with PHP and MySQL and am
I'm having difficulty with setting up a second sidebar for my Wordpress theme. Here's
I'm having difficulty figuring out why user password hashing is not working. The way
What do I need to put in a php code so that the user
I've been trying to figure out how to reformat multiple JSON files into a

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.