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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:19:11+00:00 2026-05-23T14:19:11+00:00

I am new to php and MySQL. I am making a script on my

  • 0

I am new to php and MySQL.

I am making a script on my website, that deals with mobile downloads.

I have 3 tables set up that I am dealing with here.

  1. downloads (contains info about a specific download, each with its own id).
  2. models (contains a list a possible device models(model names), each with its own id).
  3. downloads_models (linking table stating download_id = model_id, eg. (1,2) (1,3) (2,1)).

I have a simple query to display the models that support each specific download. It goes as follows:

    $dlDetailsQuery = 'SELECT models.model
    FROM models,downloads_models
    WHERE downloads_models.modId = models.model_id
    AND downloads_models.downId = "'.$pageId.'"
    ORDER BY models.model ASC; 
    ';

To display which models support the download, this line is echod:

    $dpModSupport .= stripslashes($row['model']);

Now as an example, my page has a $pageId of “1” which is the download “example1”, “example1” supports models 1(model1), 2(model2) and 3(model3). When$dpModSupport is echod, it echoes as "model1model2model3".

My question is this: how do I get spacing, or a comma between the results?

What I am aiming for is an output of “model1, model2, model3”.

I’m looking for a way to do this via php. I don’t know whether a query can be structured to output spacing between results, so I’m guessing that php is the only solution there.

I do not want to add the spacing or commas into the model name field, or create a new field containing the spacing or commas along with the model’s name.

  • 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-23T14:19:12+00:00Added an answer on May 23, 2026 at 2:19 pm

    Problem

    By writing this in a loop:

    $dpModSupport .= stripslashes($row['model']);
    

    you’re building up a string like this:

    $dpModSupport .= stripslashes(<MODEL1>);
    $dpModSupport .= stripslashes(<MODEL2>);
    $dpModSupport .= stripslashes(<MODEL3>);
    

    thus ending up with a string that’s just the contents of each row splattered next to each other.


    Solution

    Instead, you could write this before your loop:

    $dpModSupport = Array();
    

    And then, inside it, instead of the line with .= building up a string, build up the array:

    $dpModSupport[] = stripslashes($row['model']);
    

    Finally, to obtain output consisting of each element of said array, joined by a comma:

    echo implode(', ', $dpModSupport);
    

    I will leave it as an exercise to the reader to look up these functions and language features in the PHP manual.

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

Sidebar

Related Questions

PHP mysql database I have created a follow on question to this one here
I'm new to PHP/MySQL and super-new to CodeIgniter.. I have information in many MySQL
I have a php script that steps through a folder containing tab delimited files,
I'm creating a website and new to php and mysql. I just read as
I'm making a script that will hopefully be mainly PHP so it doesn't require
I am somewhat new to PHP and MySQL, and have just setup a basic
I have a PHP function that executes a MySQL query with a few variables
I started doing a new project in PHP / MySql . The Aim of
I've done a fair bit of mysql php programming but am pretty new to
I am new to MySQL and PHP(as you can probably tell) and I was

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.