Solved

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

Posted on 2012-03-28
1
286 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
[X]
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
1 Comment
 
LVL 35

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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