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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:10:22+00:00 2026-06-14T02:10:22+00:00

I am building a system, mostly for consolidating learning but will be used in

  • 0

I am building a system, mostly for consolidating learning but will be used in practice.

I will try and verbally explain the part of the E-R diagram I am focusing on:

Each cadet can have many uniformID’s

Each Uniform ID is a new entry in table uniform, so cadets (table) may look like:

id | name    | ... | uniformID

1  | Example | ... | 1,2,3

uniform table:

id | notes             | cadet

1  | Need new blahh    | 1

2  | Some stuff needed | 1

3  | Whatever you like | 1

On second thought, looks like I wont need that third column in the db.

I am trying to iterate through each id in uniformID, code:

<?php
$cadet = $_GET['id']; // set  from URL

$query = mysql_query("SELECT `uniformID` FROM `cadets` 
  WHERE id = '$cadet' LIMIT 1") 
  or die(mysql_error()); // get uniform needed as string

// store it
while ($row = mysql_fetch_array($query)) {
  $uniformArray = $row['uniformID']; 
}
echo $uniformArray . "  ";
$exploded = explode(",", $uniformArray); // convert into an array

// for each key in the array perform a new query
foreach ($exploded as $key => $value) {
  $query(count($exploded));
  $query[$key] = mysql_query("SELECT * FROM `uniform` WHERE `id` = '$value'");
}

?>

As I say, this is mainly for consolidation purposes but I have come up with a error, sql is saying:

Fatal error: Function name must be a string in C:\wamp\www\intranet\uniform.php on line 82

line 82 is:

$query[$key] = mysql_query("SELECT * FROM `uniform` WHERE `id` = '$value'");

I wasn’t sure it would work so I tried it and now i’m stuck!

EDIT:

Thanks to everyone who has contributed to this! This is now the working code:

foreach ($exploded as $key => $value) {
              //$query(count($exploded));
              $query = mysql_query("SELECT * FROM `uniform` WHERE `id` = '$value'");
              while ($row = mysql_fetch_array($query)) {
                echo "<tr>
                  <td>" . $row['id'] . "</td>
                  <td>" . $row['note'] . "</td>
                </tr>";
              }
            }

Added the while and did the iteration by nesting it in the foreach

  • 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-14T02:10:23+00:00Added an answer on June 14, 2026 at 2:10 am

    In addition to your tables

    cadets(id, ...)
    uniforms(id, ...)
    

    use a cross-product table that describes the relation between entities of cadets and entities of uniforms

    cadets_x_uniforms(cadet_id, uniform_id)
    

    For each relationship (in this case cadet x has uniform y) put a record with the respective ids into the cross-product table.

    … hm, a working example will do better in this case I suppose…

    <?php
    $pdo = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'localonly', 'localonly');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    setup($pdo);
    
    // fetch the uniforms of a specific cadet
    $stmt = $pdo->prepare('
        SELECT
            c.name,u.id,u.labelid
        FROM
            so_cadets as c
        LEFT JOIN
            so_cadet_uniform as cxu
        ON
            c.id=cxu.cadet_id
        LEFT JOIN
            so_uniforms as u
        ON
            cxu.uniform_id=u.id
        WHERE
            c.name=?
    ');
    $stmt->execute( array('cadetB') );
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    echo "uniforms of cadetB\n";
    foreach( $stmt as $row ){
        echo join(', ', $row), "\n";
    }
    
    // fetch cadets without uniforms
    $query = '
        SELECT
            c.name
        FROM
            so_cadets as c
        WHERE
            NOT EXISTS(SELECT uniform_id FROM so_cadet_uniform as cxu WHERE c.id=cxu.cadet_id)
    ';
    echo "cadets without uniforms\n";
    foreach( $pdo->query($query, PDO::FETCH_ASSOC) as $row ){
        echo join(', ', $row), "\n";
    }   
    
    
    function setup($pdo) {
        $pdo->exec('
            CREATE TEMPORARY TABLE so_cadets (
                id int auto_increment,
                name varchar(32),
                primary key(id)
            )
        ');
    
        $pdo->exec('
            CREATE TEMPORARY TABLE so_uniforms (
                id int auto_increment,
                labelid varchar(32),
                primary key(id),
                unique key(labelid)
            )
        ');
    
        $pdo->exec('
            CREATE TEMPORARY TABLE so_cadet_uniform (
                cadet_id int,
                uniform_id int,
                primary key(cadet_id,uniform_id)
            )
        ');
    
    
        $stmt = $pdo->prepare('INSERT INTO so_cadets (name) VALUES (?)');
        foreach( range('A','F') as $c ) {
            $stmt->execute( array('cadet'.$c));
        }
    
        $stmt = $pdo->prepare('INSERT INTO so_uniforms (labelid) VALUES (?)');
        foreach( range('K','Z') as $c ) {
            $stmt->execute( array('label'.$c));
        }
    
        $stmt = $pdo->prepare('INSERT INTO so_cadet_uniform (cadet_id,uniform_id) VALUES (?,?)');
        $cadetHasUniforms = array(
            1=>array(1,2,3), // <- cadetA
            2=>array(7,9), // <- cadetB
            3=>array(8,5,4), // <- cadetC
            // 4=>array() <- cadetD, no entry, no uniforms
            5=>array(10,13,15) // <- cadetE
            // <- cadetE, no entry, no uniforms
        );
        foreach( $cadetHasUniforms as $cadetId=>$uniformIds ) {
            foreach( $uniformIds as $uid ) {
                $stmt->execute(array($cadetId, $uid));
            }
        }
    
    }
    

    prints

    uniforms of cadetB
    cadetB, 7, labelQ
    cadetB, 9, labelS
    cadets without uniforms
    cadetD
    cadetF
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a system that will create a tournament based on a list of
I'm building a LMS system using Sharepoint (WSS 3.0) with the Sharepoint Learning Kit
I'm building a system health screen in a web UI for an appliance. Part
i'm building a system where users can earn XP-s. Those points are used in
I'm building a system that will send verses of scripture to subscribers over e-mail.
I am building a system to create files that will range from a few
I will be building a system where a particular object will originate from a
I'm building a system that works with web clients (Django) and remote APIs (probably
I am in the process of building a system where I need to notify
Building an inventory system. I have lots of products and each product has three

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.