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 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

Related Questions

I'm having a really difficult time trying to get php to connect to SQL
I created an object from PHP with json encode, but I am having difficulty
I'm developing a plugin in Wordpress and am having difficulty trying to post data
I am trying to create a link with php, but am having some difficulty.
I am having some difficulty running some SQL code. What I am trying to
I am having difficulty with the PHP exec() function. It seems to not be
I'm essentially having difficulty pass dynamic variables to a view. I have php functions
I'm building a small scale forum script in PHP, and I am having difficulty
I'm having some difficulty writing this code in php. I want to create a
I'm having some difficulty with this example: <img src=image1/<?php echo $file; ?>.jpg style=width:500px />

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.