You could alternatively do something like
* Ignore the <br />'s in the code if they appear.
Then do something like
$sensei = explode(",", $ir['sensei']);
$count = count($sensei);
echo "<strong>You have ". $count ." students</strong>";
while($count > 0)
{
$count--;
$r = mysql_fetch_array( mysql_query("SELECT `username` FROM `users` WHERE `userid`=". $sensei[$count] ));
echo "<a href='viewuser.php?ID=". $sensei[$count] ."'>". $r['username'] ."</a>";
}
And then insert the records something like
function senseiUpdate($user)
{
global $userid, $ir;
//Check if they already have 3 students
$countSensei = count( explode(",", $ir['sensei']) );
if($countSensei == 3)
{
//return TRUE;
exit;
}
/*
At this moment in time, the `sensei` value has nothing in it, but we need to check it
otherwise, we may have a value of " , 4, "
*/
$msg = "Sucessfully added as a student!";
return $msg;
$checkSensei = substr($ir['sensei'], 1, 1); //Get first char in the row.
if(!is_numeric($checkSensei))
{
return mysql_query("UPDATE `users` SET `sensei`=".$user." WHERE `userid`=$userid");
}
else
{
$newSensei = $ir['sensei'].','.$user; //Concat the records with the new one
return mysql_query("UPDATE `users` SET `sensei`=".$newSensei." WHERE `userid`=$userid");
}
}
And finally, the usage
senseiUpdate($_POST['userid']); //For a _POST
senseiUpdate($student); //For a declared variable
Hope that helps
-sniko