I would like to do what I have commented out in the script below. The first block of code gets the child's name out of the database. The second block of code displays the child's reading history. Is it a function or an if/else statement (or both) that I need? I don't need the code; would just like to know which PHP tool I need in this situation. I've ruled out if(isset), and I've tried adding
<?php
$num= mysqli_num_rows($result);
if ($num >0) //name was found
{
echo ".$num";
}
else
{
echo "Name not found. Please register participant.";
?>
which doesn't work. I've never written a function before, so the syntax might be the problem here. A nudge in the right direction would be appreciated. Thanks.
<?php
/*This program (search.php) takes the name that is entered and searches
*the SRC database to see if the name has already been registered.
*If the name exists, the participant's reading history is displayed.
*If the name does not exist, the registration form is displayed.
*/
include("books.inc");
$name_first = $_POST['name_first'];
$name_last = $_POST['name_last'];
$query = "SELECT * from tblparticipant WHERE name_first like '$name_first' AND name_last like '$name_last'";
$result= mysqli_query($cxn,$query)or die ("Couldn't execute query.");
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
echo "{$row['name_first']} {$row['name_last']} "; //I get the name back here, but what do I need to do to get the reading history associated with the name to display on the same screen?
}
?>
//if ($name_first,$name_last)
{
echo "$reading_history"; //$reading_history = $query="SELECT tp.name_last, tp.name_first, th.hours
FROM tblparticipant AS tp, tblhours AS th
WHERE tp.pid = th.pid
LIMIT 0 , 30";//
else if (name not in database)
echo "$name_first, $name_last is not register. Please use this form to register $name_first, $name_last.";
<?php
$name_first = $_POST['name_first'];
$name_last = $_POST['name_last'];
$hours = $_POST['hours'];
$query="SELECT tp.name_last, tp.name_first, th.hours
FROM tblparticipant AS tp, tblhours AS th
WHERE tp.pid = th.pid
LIMIT 0 , 30";