<?php

$q = intval($_GET['q']);

$con=mysqli_connect("db11.app.com","root","r123","ots");

if (!$con)
  {
  die('Could not connect: ' . mysqli_error($con));
  }
$result = mysqli_query($con,"SELECT  us.login user,WEEK(cw.create_time, '%Y-%m') AS WEEK,min(cw.create_time) ws ,max(cw.create_time) we,COUNT(*) AS total_cr  FROM 
 change_item cw,users us  where cw.create_time < now() and cw.create_by=us.id and cw.create_by = '".$q."'  GROUP BY  1,2");

	//Build Result String
echo "<table border='1'>
<tr>
<th>user</th>
<th>WEEK</th>
<th>ws</th>
<th>we</th>
<th>total_cr</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['user'] . "</td>";
  echo "<td>" . $row['WEEK'] . "</td>";
  echo "<td>" . $row['ws'] . "</td>";
  echo "<td>" . $row['we'] . "</td>";
  echo "<td>" . $row['total_cr'] . "</td>";
  echo "</tr>";
  }

echo "</table>";

?>
