please help me out in this issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dkshri_jain
Forum Newbie
Posts: 8
Joined: Tue Dec 27, 2005 12:03 am
Location: India
Contact:

please help me out in this issue

Post by dkshri_jain »

hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

Userid  NameID   Name    Amount 
       1       10          deepak  20  
       2       10         deepak  40  
       3       10        deepak  50  
       4       10        deepak  70  
       5       20        sachin  30  
       6      20         sachin  40  
       7      30          karan  10  
       8      30          karan  20  
       9      55          raj      33  
       10    55          raj     120  
       11   55           raj     40  
       12   55          raj      60
see this table okay what i want i want all 12 rows but the ouput should come like that

Code: Select all

Userid  NameID   Name    Amount 
       1       10          deepak  180  
       2       10         deepak   
       3       10        deepak   
       4       10        deepak    
       5       20        sachin  70  
       6      20         sachin    
       7      30          karan  30  
       8      30          karan    
       9      55          raj      255  
       10    55          raj       
       11   55           raj       
       12   55          raj
I can do with this select user_id,name_id,name,sum(amount),count(*) from users group by name order by user_id but in this only four record will come i want all 12 records with all first record shold contain sum .

what shold i do in the code .

Code: Select all

<?include db.php ?>

if(empty($action))
{	  echo '<br><br>';
  echo '<tr><td align=center>';
?>


	<?$count=0;
		echo '<br><br>';
		echo '<table cellspacing="1" width="700" align="center" cellpadding="3" bgcolor="#000000">';?>
	<tr bgcolor="#ffffff"><td colspan="13"><div align="left"><font size="3" color="black" face="Verdana"><b>Add Trips Entry Tool</b></font></div></td></tr>

	<?
		$res = mysql_query("select user_id,name_id,name,amount from users ");
	//$res = mysql_query("select sum(amount) as amount,name,name_id,user_id from users group by name_id");
		?>
	<?
	echo '<tr bgcolor="#000000">';
 	echo '<td><font size="1" color="white" face="Verdana">&nbsp</td>';
	echo '<td align="center"><font size="1" color="white" face="Verdana">Userid</td>';
	echo '<td align="center"><font size="1" color="white" face="Verdana">Name ID</td>';
	echo '<td align="center"><font size="1" color="white" face="Verdana">Name</td>';
    echo '<td align="center"><font size="1" color="white" face="Verdana">Amount</td>';
	
   
   

   echo '</font></tr>';
	

	$x=0;
 	while($ar = mysql_fetch_array($res)) 
		{
		
		//echo $spots;
		$x++;
		
		
		if($x==2) {$barva = "DDDDDD";$x=0;} else {$barva = "ffffff";$x=1;}
  		
				echo "<tr bgcolor=#$barva>";
			
		echo "<td align='center'>";

		$ang_id=$ar[name_id];

		 ?>
		 <td align='center'><font size='1' face='Verdana'><?echo $ar[user_id] ?> </font></td>
		 <?
			
			 echo "<td align='center'><font size='1' face='Verdana'>$ar[name_id]</font></td>";
		 	 echo "<td align='center'><font size='1' face='Verdana'>$ar[name] </font></td>";
			 echo "<td align='center'><font size='1' face='Verdana'>$ar[amount] </font></td>";
			if($ar[name_id]==$ang_id)
			{
			 $count++;
			}
			// echo $count;
		?>
		 <?

		 echo "</tr>";
   }
	
?>
<?   echo "</table><br><br><br>";

	?>








	<?
}
hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

do the summation either in php or in a separate query. Output the summation on only the first record of a given user. Keep the original query.
Post Reply