PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Saethyr
Forum Contributor
Posts: 182 Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:
Post
by Saethyr » Mon Dec 08, 2003 2:25 pm
Okay would someone have a look at this and tell me why it won't work, been staring at it for hours and cannot figure out what I did.
Code: Select all
<?php
function ListTechs($Location, $Search, $Search2, $Search3, $Cert, $Cert2)
{
@ $db = mysql_connect($DbPath, $DbUsername, $DbPassword);
if (!$db)
{
$ErrLevel = "Fatal";
echo "$ErrLevel Error: Database Busy, Please try again later!";
exit();
}
//Build Query Based on Input
$query = "SELECT distinct * FROM techinfo, skills, cert";
$query = $query.' WHERE techinfo.TechID=skill.TechID AND cert.TechID=skill.TechID';
if ($Location)
{
$query = $query.' AND techinfo.TechCity='$City'';
}
if ($Search)
{
$query = $query.' AND skill.SkillName LIKE '% $Search %'';
}
if ($Search2)
{
$query = $query.' AND skill.SkillName LIKE '% $Search2 %'';
}
if ($Search3)
{
$query = $query.' AND skill.SkillName LIKE '% $Search3 %'';
}
if ($Cert)
{
$query = $query.' AND cert.CertName LIKE '% $Cert %'';
}
if ($Cert2)
{
$query = $query.' AND cert.CertName LIKE '% $Cert2 %'';
}
$query = $query.' ORDER BY techinfo.TechLName ASC';
$result = mysql_query($query);
if ($result)
{
echo mysql_affected_rows().' Tech(s) Found.';
while($row=mysql_fetch_array($result) {
$TechID = $row["TechID"];
$thisFName = $row["TechFName"];
$thisLName = $row["TechLName"];
$resultskill = mysql_query("SELECT DISTINCT * FROM skills WHERE TechID='$TechID'", $db);
$resultcert = mysql_query("SELECT DISTINCT * FROM cert WHERE TechID='$TechID'", $db);
$thisSkill = mysql_num_rows($resultskill);
$thisCert = mysql_num_rows($resultcert);
echo <<<TECHLIST
<table border="1">
<tr>
<td>$thisFName $thisLName</td>
<td>$thisSkill Total Skills</td>
<td>$thisCert Total Certifications</td>
</tr>
</table>
TECHLIST;
}
}
}
?>
Danke,
Saethyr
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Mon Dec 08, 2003 2:30 pm
Are you sure you can have spaces between the percent sign and the string?
I'd remove them if I were you.
Also, you can shorten your code a little by going:
$query = "start string";
$query .= " and continue onward and upward.";
Saethyr
Forum Contributor
Posts: 182 Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:
Post
by Saethyr » Mon Dec 08, 2003 2:36 pm
Shortened, Thanks Thick Told you I was having a bad monday
UPDATED CODE:
Code: Select all
<?php
function ListTechs($Location, $Search, $Search2, $Search3, $Cert, $Cert2)
{
@ $db = mysql_connect($DbPath, $DbUsername, $DbPassword);
if (!$db)
{
$ErrLevel = "Fatal";
echo "$ErrLevel Error: Database Busy, Please try again later!";
exit();
}
//Build Query Based on Input
$query = "SELECT distinct * FROM techinfo, skills, cert";
$query .= ' WHERE techinfo.TechID=skill.TechID AND cert.TechID=skill.TechID';
if ($Location)
{
$query .= ' AND techinfo.TechCity='$City'';
}
if ($Search)
{
$query .=' AND skill.SkillName LIKE '%$Search%'';
}
if ($Search2)
{
$query .= ' AND skill.SkillName LIKE '%$Search2%'';
}
if ($Search3)
{
$query .= ' AND skill.SkillName LIKE '%$Search3%'';
}
if ($Cert)
{
$query .= ' AND cert.CertName LIKE '%$Cert%'';
}
if ($Cert2)
{
$query .= ' AND cert.CertName LIKE '%$Cert2%'';
}
$query .= ' ORDER BY techinfo.TechLName ASC';
$result = mysql_query($query);
if ($result)
{
echo mysql_affected_rows().' Tech(s) Found.';
while($row=mysql_fetch_array($result)) {
$TechID = $row["TechID"];
$thisFName = $row["TechFName"];
$thisLName = $row["TechLName"];
$resultskill = mysql_query("SELECT DISTINCT * FROM skills WHERE TechID='$TechID'", $db);
$resultcert = mysql_query("SELECT DISTINCT * FROM cert WHERE TechID='$TechID'", $db);
$thisSkill = mysql_num_rows($resultskill);
$thisCert = mysql_num_rows($resultcert);
echo <<<TECHLIST
<table border="1">
<tr>
<td>$thisFName $thisLName</td>
<td>$thisSkill Total Skills</td>
<td>$thisCert Total Certifications</td>
</tr>
</table>
TECHLIST;
}
}
}
?>
Last edited by
Saethyr on Mon Dec 08, 2003 2:38 pm, edited 1 time in total.
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Mon Dec 08, 2003 2:38 pm
What exactly is it doing that's wrong?
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Mon Dec 08, 2003 2:40 pm
Code: Select all
$query = "SELECT distinct * FROM techinfo, skills, cert";
$query = $query.' WHERE techinfo.TechID=skill.TechID AND cert.TechID=skill.TechID";
In the above 2nd line, wrong quote type after $query.
Actually, all your lines are affected by this.
Saethyr
Forum Contributor
Posts: 182 Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:
Post
by Saethyr » Mon Dec 08, 2003 2:45 pm
After trying to test the variables output I am seeing that my problem is in
Code: Select all
<?php
$thisSkill = mysql_num_rows($resultskill);
$thisCert = mysql_num_rows($resultcert);
?>
Can you not do the mysql_num_rows() in the way I have done it?
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Mon Dec 08, 2003 2:51 pm
That seems ok.
Hey, you're also gonna have problems ending your heredoc like that.
TECHLIST;
must start in the first column of that line.
Saethyr
Forum Contributor
Posts: 182 Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:
Post
by Saethyr » Mon Dec 08, 2003 3:48 pm
Of all the dumbass things I could have done...This fixed it and the other things seemed to have fixed it. Thanks Thick!!!! Thank God tomorrow is tuesday
Saethyr