Solved

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

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

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.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now