Hi,
I was wondering could someone help me....I have a table of names, with a list of project codes of projects they are supervising. They can supervise more than one so they might have more than one entry in the table. For example if John Jones supervises JJ1, JJ2, JJ3, he will appear in the tables 3 times.
What I need to do is to create another table, giving the name of the person, and the count of the amount of projects they are supervising, for example for John Jones it will be 3. Does anyone know a simple of piece of code that might do this for me? Here is what I have so far not sure if it makes sense!!
<?php
define ('DB_USER', 'root');
define ('DB_PASSWORD', 'password');
define ('DB_HOST','localhost');
define ('DB_NAME', 'me');
$dbc = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) OR die('Could not connect to MySql: ' . mysql_error() );
@mysql_select_db(DB_NAME)OR die('Could not select the database: ' .
mysql_error() );
?>
<?
echo "yes";
$myresult = mysql_query("SELECT * FROM staff");//count no. of members in the staff table
$num_rows = mysql_num_rows($myresult);// Display the results
$result3 = mysql_query("SELECT * FROM project_names");//count no. of projects
$num_rows1 = mysql_num_rows($result3);// Display the results
$average_num = $num_rows1/$num_rows; //average no. of projects per person
$break = floor($average_num);
$test = mysql_query("SELECT * FROM Assign");
$p = 0;
if ($result3)
{
$staff=$row2["staff"];
$project = $row2["project"];
$assig=$row2["assigned"];
//$yes = "Yes";
//$no = "No";
$ID = $row2["ID"];
while ($row2 = mysql_fetch_array($result3))
{
if($test)
{
$name=$row3["name"];
$supervising = $row3["supervising"];
$examining=$row3["examining"];
while ($row3 = mysql_fetch_array($test))
{
$supervising = 0;
$cmk = mysql_query("SELECT * FROM project_names where staff = '$staff'");
if($cmk)
{
$name = '$staff';
$supervising++;
$sql5 = "UPDATE Assign SET name = '$name' and supervising = '$supervising'";
mysql_query ($sql5);
break;
}
}
$p++;
}
}
}
?>
Thanks a million in advance