I am querying a MYSQL database and would like to return the results so that all of the job numbers that are the same are grouped together and expandable when clicking on the common name.

so when the bag loads all you see is a list of job numbers.

I have tried lots but nothing seems to work please help.

Code is attached along with screen shot of MYSQL data

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IPL - International Procurement And Logistics</title>

<link rel="stylesheet" href="../styles/login.css" media="all" />

</head>

<body>

<div class="maincontainer" align="center">

<form>

<?php

  include("../includes/connect.php");
  include("../includes/functions.php");

  if(logged_in())
  {
?>

  <div class="imgcontainer2">
    <table width="400" border="0" cellspacing="10" cellpadding="0">
      <tr>
        <td width="200" valign="top" align="left">
          <img src="../images/intro.jpg" width="100" height="100" />
        </td>
        <td width="200" valign="top" align="right">
          <p><img src="../images/logos/ipl200.gif" width="200" height="51" />
            </p>
          <p>Other Documents </p></td>
      </tr>
  </table>

  </div>

  <div width="400" class="container">

<?php

$sql = "SELECT * FROM `files` WHERE `customernumber` = 16001 GROUP BY `jobnumber` ORDER BY `fileformat` DESC";

$result = mysqli_query($con, $sql) or die("Bad Query: $sql");

$grouped = array();

echo"<table>";
echo"<tr height='20px' valign='middle'>
       <td width='80px' align='center'><strong>Job Number</strong></td>
       <td width='150px' align='center'><strong>File Type</strong></td>
       <td width='20px' align='center'><strong>Rev</strong></td>
       <td width='150px' align='center'><strong>File Name</strong></td>
     </tr>";

while($row = mysqli_fetch_assoc($result)) {

       echo"<tr height='20px' valign='middle'>
         <td align='center'>{$grouped[$row['jobnumber']]}</td>
         <td>{$grouped[$row['fileformat']]}</td>
         <td align='center'>{$grouped[$row['rev']]}</td>
         <td align='center'><a href='../documents/{$grouped[$row['filename']]}' target='new'>Click to Download file</a></td>
       </tr>";
}

echo"</table>";
?>

<?php
  }

  else
  {
    header("location:../login.php");
    exit();
  }
?>

  </div>

</form>

</div>

</body>
</html>

Just some thoughts.

  1. Right off the top an easy change would be to sort by the job number so what belongs together is together. No, does not address your other wants.
  2. To me this would be a lot more code. In fact it may not be worth the time and effort you will expend on this. How about another idea? Why not give a screen with just the job numbers and job titles which you click on and get another page with the records for that job?
  3. OK, you really want collapsible lists? https://www.google.com/search?q=collapsible+html+lists finds ideas on this but to make it work I think you'd have to code it so each list is for each job number. So you start with a SQL query to count how many unique jobs there are and then iterate each job number to make the list, then more code to fill that list and so on.
  4. For me, this is too much to work and has some harsh downsides. For example SQL lets us have a multiuser database and your big screen with all jobs and lists could be out of date in seconds. My advice is to go with thought #2.
Member Avatar for diafol

I have tried lots but nothing seems to work please help.

How about posting to the appropriate forum?

BTW $grouped is just an empty array. What is it supposed to do?

commented: A mystery to me why folk post this in a community center. Watching Parks and Rec too much? +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.