php - MySql and MySqli Left Join -


i have been having trouble past couple of hours trying wrap head around way pull similar data 2 different tables. have playing around join statements have been unable accomplish i'm trying do..

first trying pull list of clients , display them , information table in html table (this complete). secondly, take index (known mid) , use reference data in table contains more data on mid. each client has multiple "projects" located in table, , each 1 of these projects has value called "package" value can either 1,2, or 3. able pull customer data 1 table, , pull total number of each package have. i.e in table have blank place pack1, pack2, pack3, hope contain total number of rows contain number in package same mid.

example [ name ] [totalprojects][ totalpackage1][totalpackage2][totalpackage3]           bob          25               4               12             9 

here code

$query_load_accounts = "select * useraccounts order mid"; $result_load_accounts = mysqli_query($dbc, $query_load_accounts);  echo '<center><table border="1">'; echo '<cellpadding="10">'; echo '<th>company name</th>'; echo '<th>member since</th>'; echo '<th>package 1</th>'; echo '<th>package 2</th>'; echo '<th>package 3</th>'; while ($row = mysqli_fetch_assoc($result_load_accounts)) {  echo "<tr> <td><center>{$row['company']}</td></center> <td><center>membersince</center></td>  <td><center>notused</center></td>  <td><center>package1</center></td> <td><center>package2</center></td> <td><center>package3</center></td>";  }   echo "</center></table>"; mysqli_close($dbc); mysqli_free_result($result_load_accounts); 

other useful information - other table's name "projects" , fields needed mid (customer specific) , package (just package number i.e package 1 14.99, package 2 24.99 ext) able guess use join statement total amount of each package each user.. im having trouble it

*update have tested following statement , pulls data correctly, need know how sort data in php. i.e count rows each user

$query_load_accounts = "select useraccounts., projects. useraccounts left join tributes on useraccounts.mid = projects.mid order uid";


thanks 0 activity in thread have resolved issue myself. riddance.

'select mid, sum(if(package = "1", 1,0)) `1`, sum(if(package = "2", 1,0)) `2`, sum(if(package = "3", 1,0)) `3`, count(package) `total` projects group mid order mid desc' 

'select mid, sum(if(package = "1", 1,0)) 1, sum(if(package = "2", 1,0)) 2, sum(if(package = "3", 1,0)) 3, count(package) total projects group mid order mid desc'


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -