[SOLVED] Show link to document problem -- help

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

Post Reply
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

[SOLVED] Show link to document problem -- help

Post by melindaSA »

I have the following code, that works, except that I want to show the link to the resume (if it exists). It, however only shows on the last entry of the results and not all results. What am I doing wrong.....pulling my hair out!!

Code: Select all

<?php
$query = "SELECT * from application ORDER by appID DESC";

$result = mysql_query($query)
        or die ("could not execute query");

echo "<table>\n";
echo "<tr align="left"><th width="120"><font face="Verdana" size="1"><b>Applicant Name</b></font></th>
      <th width="120"><font face="Verdana" size="1"><b>Position Applied</b></font></th>
      <th width="120"><font face="Verdana" size="1"><b>Application</b></font></th>
      <th width="120"><font face="Verdana" size="1"><b>Date</b></font></th>
      <th width="80"><font face="Verdana" size="1"><b>Resume</b></font></th></tr>\n";
      

while ( $row = mysql_fetch_array($result))
{
   extract($row);
   echo "<tr>\n";
   echo "<td width="120"><font face="Verdana" size="1">$first_name $last_name</font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1">$position_apply</font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1"><a href="../show_app.php?appID=$appID" target="_blank">view application</a></font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1">$date</font><br></td>\n";
}

if(!file_exists("../resume/".$first_name.$last_name.".doc")){
echo "<td width="80"><font face="Verdana" size="1"><a href="../resume/".$first_name.$last_name.".doc">Yes</a></font><br></td>\n";
} else {

echo "<td width="80"><font face="Verdana" size="1">No</font><br></td>\n";
}
   echo "</tr></table>\n";
?>
Last edited by melindaSA on Mon Feb 16, 2004 5:34 pm, edited 1 time in total.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

You have the following code:

Code: Select all

<?php
if(!file_exists("../resume/".$first_name.$last_name.".doc")){ 
?>
Yet this outputs the "Yes" link? SHouldn't this be:

Code: Select all

<?php
if(file_exists("../resume/".$first_name.$last_name.".doc")){ 
?>
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

If I remove ! it changes to no even if there is a resume posted
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Are you sure you have the correct path then? And that the filename is correct? Try this for debugging and see if the path and filename are correct.

Code: Select all

<?php
echo "../resume/".$first_name.$last_name.".doc";
?>
I assume you understand that ../ means the link will go up a directory.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Yes, it is working. Maybe I am not explaining my problem correctly. Here is a sample of the output that I am getting (I have replaced the
Applicant names with xxxxxxx)
Applicant Position Applied Application Date Resume
Name
xxxxxxxx Housekeeping view application 0000-00-00
xxxxxxxxx Housekeeper view application 0000-00-00
xxxxxxx cna2 view application 0000-00-00
xxxxxxxx CNA1 view application 0000-00-00
xxxxxxxx CNA1 view application 0000-00-00
xxxxxxxxx NURSE view application 0000-00-00
xxxxxxx Secretary view application 0000-00-00
xxxxxxxxx Unit Secretary view application 0000-00-00
xxxxxxxx CNA I FT/PT view application 0000-00-00
xxxxxxxx Optical Specialist view application 0000-00-00
xxxxxxxxx Unit Secretary view application 0000-00-00
xxxxxxxxx CLERK view application 0000-00-00
xxxxxxxxxx CNA view application 0000-00-00
xxxxxxxxx Therapist view application 0000-00-00
xxxxxxxxxx Unit Secretary view application 0000-00-00
xxxxxxxxxx Unit Secretary view application 0000-00-00 Yes
As you will see, The only entry that is showing Yes (resume there) is the last entry. None of the others are showing yes or no.

Hope this makes sense!
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

AHH! I guess I was making this a little harder then it need to be. All you need to do is put the "if(file_exists)" inside the "while" loop. :D Right now, the entire while loop executes and then it goes on the the "if(file_exists)".

Here is how it should look:

Code: Select all

<?php
while ( $row = mysql_fetch_array($result))
{
   extract($row);
   echo "<tr>\n";
   echo "<td width="120"><font face="Verdana" size="1">$first_name $last_name</font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1">$position_apply</font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1"><a href="../show_app.php?appID=$appID" target="_blank">view application</a></font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1">$date</font><br></td>\n";\

if(!file_exists("../resume/".$first_name.$last_name.".doc")){
echo "<td width="80"><font face="Verdana" size="1"><a href="../resume/".$first_name.$last_name.".doc">Yes</a></font><br></td>\n";
} else {

echo "<td width="80"><font face="Verdana" size="1">No</font><br></td>\n";
} 

} //END WHILE LOOP


?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

the file exist code section isnt inside the while loop...

:/edit - oops, was a lil late... kudos
Last edited by tim on Mon Feb 16, 2004 5:22 pm, edited 1 time in total.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

As I stated before, it should though. I even gave you the above code, just replace the while and if loops in your current code with the above code.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

yeah duff thats what I was saying but you just posted before me along with the correct code...

wasnt disagreeing with you at all :D just saying the problem

kudos partner
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

OH! haha, i thought you were the original poster!! :P :D

It's all good.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thanks, that fixes that problem, but now it is showing yes for all entries even if there is no resume......
:?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Whoops, make sure you've got this line then:

Code: Select all

<?php
if(file_exists("../resume/".$first_name.$last_name.".doc")){ 

//REPLACES: if(!file_exists("../resume/".$first_name.$last_name.".doc")){
?>
It shouldn't have the "!" that I had in the above code.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

:oops: THANK YOU, it now works great!
Post Reply