Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Query as student id and show it as total pay. I was post before about this problem. maybe I was not able to clear my question.so I post it again. please help me

http://i.stack.imgur.com/SuYwb.jpg

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

?>


<?php
$sql0="SELECT * FROM payment as std_id GROUP BY std_id ";
$sql="SELECT SUM(pay) FROM payment as std_id GROUP BY std_id ";
$result0=mysql_query($sql0);
$result=mysql_query($sql);
?>






<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="6"><div align="center"><strong>List data from mysql </strong> </div></td>
</tr>

<tr>
<td align="center"><strong>std id</strong></td>
<td align="center"><strong>pay</strong></td>



<?php
while($rows0=mysql_fetch_array($result0))  {
?>

<tr>
<?php
while($rows=mysql_fetch_array($result))  {
?>

<td><?php echo $rows0['std_id']; ?></td>
<td><?php echo $rows['SUM(pay)']; ?></td>



</tr>

<?php
}
}
?>



</table>
</td>
</tr>
</table>




<?php
mysql_close();
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
161 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this:

Here you need to get amount Student wise, so need to do GROUP BY student & also want sum amount, so need to call SUM function and pass amount in it.

Here is MySQL Query:

SELECT std_id AS studentid , SUM(pay) as Amount 
FROM table 
GROUP BY std_id;

Let me know if you need further help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...