Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Is it possible to get the total of each different item use by users in a table and than add the total to the matching item in another table?

$
0
0

Hi i spend hours on this and i have search all over but i couldn't find the right code.I already know how to count the items.below is the sql code i use to test .

 

 

 

 

 

 

 

SELECT Items.item
FROM Items
LEFT OUTER JOIN (

SELECT item, COUNT( item )
FROM Members

GROUP BY item

)Members ON Items.item = Ad.Members

 

i don't get the results i want with above.


 

echo "<h4>Members
table:</h4>
<table border=\"1\">
<tr>
  <th>username</th>
  <th>item</th>
 </tr>
<tr>
  <td>kim</td>
  <td>orange</td>
 </tr>
<tr>
  <td>tom</td>
  <td>apple</td>
 </tr>
</table>
<br><br>

 

<h4>Items table:</h4>
<table border=\"1\">
<tr>
  <th>item</th>
 </tr>
<tr>
  <td>orange</td>
</tr>
<tr>
 <td>apple</td>
 </tr>
<tr>
 <td>grape</td>
 </tr>
</table>
<br><br>

 

 

<h4>I want to get this table:</h4>
<table border=\"1\">
<tr>
  <th>item</th>
  <th>COUNT(item)</th>
 </tr>
<tr>
  <td>orange</td>
<td>1</td>
 </tr>
<tr>
  <td>apple</td>
  <td>1</td>
</tr>
<tr>
 <td>grape</td>
 <td></td>
 </tr>
</table>";

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles