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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:39:39+00:00 2026-06-09T02:39:39+00:00

I have a database table like below: id | igroup | title | url

  • 0

I have a database table like below:

id | igroup | title     | url          | text
1  |   gr1  | Title 1   | urltoimage1  | text1
2  |   gr1  | Title 2   | urltoimage2  | text2
3  |   gr2  | Title 3   | urltoimage3  | text3
4  |   gr2  | Title 4   | urltoimage4  | text4

I mean, i want to have an multidimensional array (for above structure) like below;

$result[gr1] = [Title 1|urltoimage1][Title 2|urltoimage2]
$result[gr2] = [Title 3|urltoimage3][Title 4|urltoimage4]

Finally, I’ll send this $result array to page via JSON.

So, in my page I’ll arrange these values for classified image gallery, like:

Group 1(caption text)
--------
image1 image2 (clickable images)

Group 2(caption text)
--------
image3 image4 (clickable images)

Edit: i corrected group field by igroup.

Question revised.

  • 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-09T02:39:41+00:00Added an answer on June 9, 2026 at 2:39 am

    You will need to fetch the results using the ORDER BY statement added to your query.

    SELECT id, igroup, title, url, text
    FROM images
    ORDER BY igroup;
    

    Warning:

    Please, don’t use mysql_* functions to write new code. They are no longer maintained and the community has begun the deprecation process. See the red box?

    Instead, you should learn about prepared statements and use either PDO or MySQLi. This article should give some details about deciding which API to use. For PDO, here is a good tutorial.

    Example code:

    $result = mysql_query(THE_STATEMENT_ABOVE);
    
    $groups = array();
    while ( $row = mysql_fetch_assoc($result) )
        $groups[ $row['igroup'] ][] = $row;
    

    This will build up a nice $groups array. To parse the array created above, you might either use Iterators or simple foreach constructs.

    foreach ( $groups as &$one_group ) {
        print("Group 1: <br>");
    
        foreach ( $one_group as &$one_image ) {
            // Here you have the contets of the previously fetched $row rows of the result.
            print('<a href="' .$one_image['url']. '">' .$one_image['title']. '</a><br>');
        }
    }
    

    This will give you a nice output like this below:

    Group 1:
    Image 1 (clickable)
    Image 2 (clickable)
    
    Group 2:
    Image 3 (clickable)
    Image 4 (clickable)
    

    No longer applies: Also, you should refrain from using GROUP as a field name, as it is one of the reserved MySQL words.

    Edit: I have also corrected the field name to igroup.

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

Sidebar

Related Questions

I have a mysql database with a table structure like below : Table Name
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
need help in error in database pivot. i have table tamed table_score like below:
I have a database table that has a structure like the one shown below:
I have a table (in an Oracle database) just like below: department ---------- Finance
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
Say I have a database table like the following: FileID | FileName | FileSize
Let's say you have a database with a single table like... --------------------------------------------- | Name
I always forget how to do things like this. I have a database table

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.