Solved

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

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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