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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:56:44+00:00 2026-05-25T17:56:44+00:00

Okay, I’m kinda stuck on really silly problem, but still can’t figure out. I’m

  • 0

Okay, I’m kinda stuck on really silly problem, but still can’t figure out.

I’m having an array from database with mysql_fetch_array. So far I have only 1 record in the table and after print_r(….) I have this:

Array (
   [0] => 1 
   [customer_id] => 1 
   [1] => Test Client 
   [customer_name] => Test Client 
   [2] => 
   [customer_image] => 
   [3] => Test Address 
   [customer_address] => Test Address 
   [4] => 2272723 
   [customer_phone] => 2272723
)

I’m trying to make a foreach() {...} from where I’ll get customer_id and customer_name

and somehow I can’t make correct foreach to get them and I’m getting some hilarious results…

any ideas?

=================

$sql = "SELECT * FROM customers";
$result_set = mysql_query($sql, $this->connection);
$records = mysql_fetch_array($result_set);

function generateSelect($recordName, $label, $default) {
        $records = parent::selectTableRecord($recordName);
      $html = "<label for=\"".$recordName."\">". $label ."</label>";
      $html .= "<select name=\"". $recordName ."\" id=\"". $recordName ."\">";
      $html .= "<option value=\"\">". $default ."</option>";
          while ($record = mysql_fetch_assoc($records)) {
            $html .= "<option value=\"".$record['customer_id']."\">".$record['customer_name']."</option>";
          }
      $html .= "</select>";
      return $html; 
    }

and somewhere on other page I’m echoing this function:

<?php echo Project::generateSelect('customer', 'client', '--'); ?>

here’s what I have

  • 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-25T17:56:44+00:00Added an answer on May 25, 2026 at 5:56 pm

    the easiest way would be to use this code :

    $result = mysql_query("SELECT * FROM customer");
    while($posts = mysql_fetch_array($result)){
    echo $posts['customer_name'];
    }
    

    Updated answer to reflect the exact vars used in the question

    $sql = "SELECT * FROM customers";
    $result_set = mysql_query($sql, $this->connection);
    while($records = mysql_fetch_array($result_set)){
       echo $records['customer_name'];
    }
    

    now #customer_name can be replaced by ANY field name you have in that table to get that data.

    and if you wanted to use foreach to have $i as a number to keep track of the number of results, then you can create $i = 0; outside the while() and at the end before closing it, just add $i++.

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

Sidebar

Related Questions

Okay so I can't figure this out. Like a file that I using grep
Okay I got some good advice for Mobile Detection but still having an issue
Okay, I feel a bit foolish for having to ask this but I guess
Okay, so the answer to my question might not be the problem but here's
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
Okay. So I'm creating this app and I'm really happy with it apart from
Okay, I kinda asked this question already, but noticed that i might have not
Okay, this is quite related to my previous quesion , but still (so you
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay, this is probably a very basic question; but, I'm just getting back in

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.