Solved

PHP script to show DB returns but group query by like names

Posted on 2012-03-28
1
282 Views
Last Modified: 2012-03-28
I'm not sure the best way to ask, but need what I am assuming may be a simple solution.

I have queried by database to return all values by 'groupID' that have a value of '0'.

There are several items returned that are the same 'groupID'.

I only need it to show those groups once, as the name will be a link to a detail page to return each line for that group.

Below is what i have tried, there are 9 records on my test server with a value of '0' but it duplicates the groups currently into 5 records.

sorry, it's Dreamweaver code.

mysql_select_db($database_con_portal_test, $con_portal_test);
$query_rs_console = "SELECT tblgroup.grpID, tblgroup.grpName, tblinfo1.groupID, tblinfo1.trnsProcessed, tblinfo1.transID FROM tblgroup, tblinfo1 WHERE tblinfo1.trnsProcessed = '0' AND tblgroup.grpID = tblinfo1.groupID";
$rs_console = mysql_query($query_rs_console, $con_portal_test) or die(mysql_error());
$row_rs_console = mysql_fetch_assoc($rs_console);
$totalRows_rs_console = mysql_num_rows($rs_console);

 <?php
// initialize variables
$previous = '';
$first = true;
do {
  // if not the same value as $previous
  if ($row_rs_console['grpName'] != $previous) {
  	
    // if not the first time, close the nested list
    
    // display the category
    echo $row_rs_console['grpName'] . $row_rs_console['trnsID'] . '<br />';
   
    // store the current value for comparison next time
    $previous = $row_rs_console['grpName'];
	$first = false;
  }
 
  // it's no longer the first time

  } while ($row_rs_console = mysql_fetch_assoc($rs_console)); ?>

Open in new window

0
Comment
Question by:axessJosh
1 Comment
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 37777822
Try adding this to the end of your query:

GROUP BY tblgroup.grpID
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question