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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:57:50+00:00 2026-06-16T09:57:50+00:00

Originally, this simple array and a foreach statement works perfect, but I need to

  • 0

Originally, this simple array and a foreach statement works perfect, but I need to change from a php array to getting the information out of the database:

$serversArray = array(
    "domainname1.com",
    "domainname2.com:port",
    "domainname3.org",
    "000.000.000.000:port");

foreach($serversArray as $server)

.

ID    IP                Port
1     domainname1.com   
2     domainname2.com   12345
3     domainname3.org   
4     000.000.000.000   54321

What I need to figure out is how to get the IP and Port columns formatted into ip:port (with the colon in between), and then make the foreach statement recognize each one so it can process it with some other script, just like how it works already with the array. (I have also tried using sprintf in the foreach, but that broke the page.)

  • 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-16T09:57:51+00:00Added an answer on June 16, 2026 at 9:57 am

    Do you want build the $serversArray from a DB query?

    $serversArray = array();
    $sql     = "SELECT ip, port FROM my_table";
    $result = mysql_query($sql);
    while ($row  = mysql_fetch_array($result))
    {
        // if have port include it after : otherwise just include ip
        $serversArray[] = $row['port'] ? "{$row['ip']}:{$row['port']}" : $row['ip'];
    }
    

    Old fashion sql queries are just to show the procedure to build the array. At the present time we should use MySQL Functions (PDO_MYSQL)

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

Sidebar

Related Questions

$_SESSION[{'\'testingrecord'.$testingrecordsfec.'\''}] this originally looked like this ${'testingrecord'.$testingrecordsfec} but I need to add the variables
Working on converting an array to another array. In PHP, this is easy, but
I originally started this question in another thread, but that thread was sorta, kinda
Note: I originally asked this question about an hour ago but only recently realized
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
I originally used JQuery for this project, but now I'm having to use Prototype,
This code comes from a tutorial so it's not originally my own work. What
Im building a simple album and track webapp but im getting into a pickle
Okay, so this seems simple, but I can't think of a straightforward solution; Basically
I am getting the key from a given value in a multidimensional array. It

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.