Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2012-03-28
1
283 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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

861 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