PHP Array from Checkbox > Display Results based on checkbox and Database Query

lwaters5
02:14:13
I am trying to have a list of students with a checkbox next to them. You select the students you want to see and hit submit. The array is then sent to the next page, where it queries a database for the UIDs of the students that you selected and displays there profiles. The data displayed in the profiles is in multiple tables but the UID is unique to each student. For some reason, I get no errors but, nothing shows up. Here is my code:

Page 1: Form
<form id="form1" name="form1" method="post" action="printable_version2_test3.php">
<?php do { ?>
<p>
<input name="UID[]" type="checkbox" id="UID" value="<?php echo $row_applicants['UID']; ?>" />
<label for="UID"></label>
<?php echo $row_applicants['FNAME']; ?> <?php echo $row_applicants['LNAME']; ?> </p>
<?php } while ($row_applicants = mysql_fetch_assoc($applicants)); ?>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<input name="ID" type="hidden" id="ID" value="<?php echo $_GET['ID']; ?>" />
</p>
</form>


Page 2: Display Results
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$selected = array();
if (isset($_POST['UID']) && is_array($_POST['UID'])) {
$selected = $_POST['UID'];
} else {
$selected = array($_POST['UID']);
}
$ID = $_POST['ID'];
}
mysql_select_db($database_connect, $connect);
$idList = implode(',', $_POST['UID']);
$sql = "SELECT *, scholarships.NAME as scholarshipname FROM scholarships, users INNER JOIN stu_app2008 ON users.UID = stu_app2008.UID LEFT JOIN activities ON users.UID = activities.UID LEFT JOIN coll_exp ON users.UID = coll_exp.UID LEFT JOIN employ ON users.UID = employ.UID LEFT JOIN fin_app ON users.UID = fin_app.UID LEFT JOIN finaid ON users.UID = finaid.UID LEFT JOIN stu_special ON users.UID = stu_special.UID WHERE scholarships.ID = $ID and users.UID in (' . $idList . ')";
$res = mysql_query($sql) or die(mysql_error());
$varlist = array();
while ($row = mysql_fetch_assoc($res)) {
$varlist[$row['UID']] = $row;

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="Cambridge Public Schools: Public schools built on a foundation of academic excellence and committed to promoting an environment of social justice.">
<meta name="keywords" content="cambridge, massachusetts, ma, mass, public, school, district, k-12, public schools, cambridge public schools, school registration, cambridge schools, ma public schools, rindge and latin school, amigos school, morse school, tobin school, peabody school, fletcher-maynard academy, kennedy-longfellow, rindge school of technical arts, baldwin school, cambridgeport, graham & parks, haggerty school, martin luther king jr. school, cambridge rindge and latin, crls, falcon sports, superintendent young, cps">
<meta name="robots" content="noarchive">
<link rel="shortcut icon" href="http://www3.cpsd.us/media/ImageElements/theme/CPS%20Redesign/favicon.ico?rev=1">
<link rel="stylesheet" type="text/css" href="https://secure2.cpsd.us/scholarship/form_styles.css" />
<style type="text/css">td img {display: block;}</style>
<style type="text/css">td img {margin: 0;}</style>
<link href="../text.css" rel="stylesheet" type="text/css" />
<style>
.break { page-break-before: always; }
</style>
<title>Cambridge Rindge &amp; Latin School | 2012 Scholarship Standard Application</title>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=600,height=500,scrollbars=yes');
return false;
}
//-->
</SCRIPT>

</head>

<body><?php
foreach ($varlist as $UID => $row)
do { ?>
<table border="0" cellspacing="0" cellpadding="0" width="960px" align="center">
<tbody>
<tr>
<td colspan="3" valign="top">
<table style="width: 100%;" border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td width="100%" valign="top">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td valign="top" class="break"><strong><?php echo $row['FNAME']; ?>&nbsp;<?php echo $row['LNAME']; ?> | <?php echo $row['scholarshipname']; ?></strong></td>
</tr>
<tr>
<td width="100%" valign="top"><br>
<h6>2012 Scholarship Standard Application</h6>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
<td colspan="7" valign="top"><table width="98%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr>
<td width="200%" colspan="2" valign="top"><fieldset id="el11"><legend><strong>Section 1: Applicant Information</strong></legend>
<table width="100%" border="0" cellspacing="1" cellpadding="6">
<tr bgcolor="#cccccc">
<td width="33%" valign="top"><strong>Name: </strong><?php echo $row['FNAME']; ?>&nbsp;<?php echo $row['LNAME']; ?></strong></font></strong></td>
<td valign="top"><strong>Gender: </strong><?php echo $row['GENDER']; ?></strong></font></strong></td>
<td valign="top"><strong>SID: </strong><?php echo $row['SID']; ?></strong></font></strong></td>
</tr>
<tr>
<td colspan="2" valign="top" bgcolor="#FFFFFF"><strong>Address: </strong><?php echo $row['ADDRESS']; ?></strong></font></strong></td>
<td valign="top" bgcolor="#FFFFFF"><strong>Homeroom: </strong><?php echo $row['HR']; ?></strong></font></strong></td>
</tr>
<tr bgcolor="#cccccc">
<td valign="top"><strong>Telephone: </strong><?php echo $row['TEL']; ?></strong></font></strong></td>
<td valign="top"><strong>LC: </strong><?php echo $row['LC']; ?></strong></font></strong></td>
<td valign="top"><strong>GC: </strong><?php echo $row['NAME']; ?></strong></font></strong></td>
</tr>
<tr>
<td valign="top" bgcolor="#FFFFFF"><strong>Email: </strong><?php echo $row['UNAME']; ?></strong></font></strong></td>
<td colspan="2" valign="top" bgcolor="#FFFFFF"><strong>Elementary School:</strong> <?php echo $row['ELEM']; ?></td>
</tr>
</table></fieldset></td>
</tr>
<tr>
<td colspan="2" valign="top"><fieldset id="el11">

....and so on


Thank you for your help. I am an extreme newbie and have been searching all over to fix my issue but with no results.
smo1234
02-14-2013
It is difficult to check the full code like this. You have to be specific. Post the error message you are getting. Before that see your form is displaying all the students list or not. Then after selection the selected student list is available at second page or not ( ids of the student ).


Then try for displaying the list of profiles.
lwaters5
02-15-2013
There is no error message. Just get a blank screen. Nothing is displayed including the tables holding the profiles. The ID of the students is a field called UID. I am wondering if the error is in this line of code:

<?php
foreach ($varlist as $UID => $row)
do { ?>
smo1234
02-15-2013
Before using the UID for the database query, just try to display to screen. In the second page you can just check the list of UID. That should first come.
Is it coming to 2nd page?
lwaters5
02-15-2013
When I do that it just says Array instead of all the UIDs.
smo1234
02-15-2013
ok then you mus display the elements of the array first. What you are selecting you should get those UID numbers only.

If this part is ok then go for next part that is using this data to develop the query and displaying the data.
Please Login to post your reply or start a new topic