Best way to write php script
Posted: Tue Sep 09, 2003 4:54 pm
I am getting data from two tables,
certs: which contains columns ID and CERTS. This table contains a list of various certifications by name and vendor.
faccerts: which contains columns ID, FID, CID. CID is relational to ID.certs. FID will be a number coresponding to a particular faculty ID which is passed via GET method (assigned to variable $fid). This table contains a reference to the various certifications a faculty member has.
I want to create a loop which will check FID against the $fid. Each time $fid matches FID in the faccerts table, I want to print out the corresponding CERT in the certs table.
I'm not sure of how to write the php for the SELECT statement to get the certification (CERTS.certs). The general idea is written below but obviously I'm missing some php elements but I wanted to convey what I'm trying to do.
$certs_array = @mysql_query("SELECT ID.certs, CERTS, FID, CID FROM certs, faccerts");
while ($faccerts = mysql_fetch_array($certs_array)) {
$facid_faccerts = $faccerts['FID'];
if ($fid == $facid_faccerts) {
select CERTS WHERE CID=ID.certs (I know this is not the correct way to write it but I want to convey what I want to do)
echo (print the certification listed in the certs table);
}
}
I know I can stumble through getting the results I want but the code would probably look like it went through a meat grinder. Will you help me with the code as I'm new to both php and mysql and I want to learn good coding skills. Thanks.
certs: which contains columns ID and CERTS. This table contains a list of various certifications by name and vendor.
faccerts: which contains columns ID, FID, CID. CID is relational to ID.certs. FID will be a number coresponding to a particular faculty ID which is passed via GET method (assigned to variable $fid). This table contains a reference to the various certifications a faculty member has.
I want to create a loop which will check FID against the $fid. Each time $fid matches FID in the faccerts table, I want to print out the corresponding CERT in the certs table.
I'm not sure of how to write the php for the SELECT statement to get the certification (CERTS.certs). The general idea is written below but obviously I'm missing some php elements but I wanted to convey what I'm trying to do.
$certs_array = @mysql_query("SELECT ID.certs, CERTS, FID, CID FROM certs, faccerts");
while ($faccerts = mysql_fetch_array($certs_array)) {
$facid_faccerts = $faccerts['FID'];
if ($fid == $facid_faccerts) {
select CERTS WHERE CID=ID.certs (I know this is not the correct way to write it but I want to convey what I want to do)
echo (print the certification listed in the certs table);
}
}
I know I can stumble through getting the results I want but the code would probably look like it went through a meat grinder. Will you help me with the code as I'm new to both php and mysql and I want to learn good coding skills. Thanks.