Looping through an array
Posted: Tue Sep 16, 2003 5:16 pm
I have two tables.
Table 1: certs.
contains certs.ID and certs.CERTS. The certs.CERTS column is a list of various certifications such as Microsoft, Novell, A+, etc.
Table 2: faccerts.
contains faccerts.ID - primary key
faccerts.FID - corresponds to the faculty ID in another table. This information is passed to the function.
faccerts.CID - corresponds to certs.ID above.
I am trying to print out a listing of certifications an individual faculty member. I've created a function to do this:
The problem I'm having is that only one certification is being printed out, and that certification is being printed out twice. Say for example, an instructor is a CIW and CNE. The CNE cert has lower cert.ID (3) than cert.CIW (14). When I click the link to list the certs for that instructor, the CNE cert gets printed twice and the CIW cert doesn't get printed at all. Will you help me get the code correct for this? Thanks.
Table 1: certs.
contains certs.ID and certs.CERTS. The certs.CERTS column is a list of various certifications such as Microsoft, Novell, A+, etc.
Table 2: faccerts.
contains faccerts.ID - primary key
faccerts.FID - corresponds to the faculty ID in another table. This information is passed to the function.
faccerts.CID - corresponds to certs.ID above.
I am trying to print out a listing of certifications an individual faculty member. I've created a function to do this:
Code: Select all
function listfaccerts($fid) {
$sql_query = @mysql_query("SELECT certs.CERTS FROM certs, faccerts WHERE faccerts.FID='$fid' AND certs.ID=faccerts.CID");
if (!$sql_query) {
echo ("Error in sql query: " . mysql_error());
}
$allcerts = mysql_fetch_array($sql_query);
foreach ($allcerts as $eachcert) {
echo ('<p align="center">'.$eachcert.' <br>');
}
} // End List of Faculty Certifications