Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

how to make a link only if exists

 
   Database Forums (Home) -> PHP SQL RSS
Next:  New website written in PHP, MySQL  
Author Message
Henny Boxa

External


Since: Mar 25, 2008
Posts: 2



(Msg. 1) Posted: Fri Apr 18, 2008 7:11 pm
Post subject: how to make a link only if exists
Archived from groups: alt>php>sql (more info?)

On my site is a database of articles in a few journals. The visitor
can get information by asking for the name of an author or a word in
the articles title. So far so good.
Some, but not all of the articles are in PDF. I would like to give the
visitor the opportunity to get the PDF file, but I want to present the
link only if there is a PDF file for this title. Is that possible?
At present the situation is:
while ($row=mysql_fetch_row($result))
{
echo"<td>$row[0]</td>";
echo"<td><a href=\"$row[5].pdf\">$row[1]</a></td>";
etcetera all relevant rows
}
As probably is clear row[0] contains authors, row[1] contains titles,
other row are used for finding place and in row[5] is the id of the
article (idart). This number is in the query but it is not presented
to the visitor. So the name of the PDF file is idart.pdf.
Should I make an if statement within the link?
Thank you,
Henny

 >> Stay informed about: how to make a link only if exists 
Back to top
Login to vote
J.O. Aho

External


Since: Dec 01, 2003
Posts: 397



(Msg. 2) Posted: Fri Apr 18, 2008 8:24 pm
Post subject: Re: how to make a link only if exists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Henny Boxa wrote:
> On my site is a database of articles in a few journals. The visitor
> can get information by asking for the name of an author or a word in
> the articles title. So far so good.
> Some, but not all of the articles are in PDF. I would like to give the
> visitor the opportunity to get the PDF file, but I want to present the
> link only if there is a PDF file for this title. Is that possible?
> At present the situation is:
> while ($row=mysql_fetch_row($result))
> {
> echo"<td>$row[0]</td>";
> echo"<td><a href=\"$row[5].pdf\">$row[1]</a></td>";
> etcetera all relevant rows
> }
> As probably is clear row[0] contains authors, row[1] contains titles,
> other row are used for finding place and in row[5] is the id of the
> article (idart). This number is in the query but it is not presented
> to the visitor. So the name of the PDF file is idart.pdf.
> Should I make an if statement within the link?

if(file_exists($row[5].'.pdf')) {
echo "<a href=\"$row[5].pdf\">$row[1]</a>";
}

--

//Aho

 >> Stay informed about: how to make a link only if exists 
Back to top
Login to vote
Henny Boxa

External


Since: Mar 25, 2008
Posts: 2



(Msg. 3) Posted: Sat Apr 19, 2008 7:28 pm
Post subject: Re: how to make a link only if exists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Fri, 18 Apr 2008 20:24:54 +0200 wrote "J.O. Aho"
:

>Henny Boxa wrote:
>> On my site is a database of articles in a few journals. The visitor
>> can get information by asking for the name of an author or a word in
>> the articles title. So far so good.
>> Some, but not all of the articles are in PDF. I would like to give the
>> visitor the opportunity to get the PDF file, but I want to present the
>> link only if there is a PDF file for this title. Is that possible?
>> At present the situation is:
>> while ($row=mysql_fetch_row($result))
>> {
>> echo"<td>$row[0]</td>";
>> echo"<td><a href=\"$row[5].pdf\">$row[1]</a></td>";
>> etcetera all relevant rows
>> }
>> As probably is clear row[0] contains authors, row[1] contains titles,
>> other row are used for finding place and in row[5] is the id of the
>> article (idart). This number is in the query but it is not presented
>> to the visitor. So the name of the PDF file is idart.pdf.
>> Should I make an if statement within the link?
>
>if(file_exists($row[5].'.pdf')) {
> echo "<a href=\"$row[5].pdf\">$row[1]</a>";
>}

Thank you very much indeed.
 >> Stay informed about: how to make a link only if exists 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
PHP / MySQL on Fedora - can't make it work - Hi, I can't figure out why PHP can't access any MySQL databases on my Fedora 2.6.8. I have no problem executing php scripts that do not deal with MySQL. Also, I have no problem accessing MySQL databases using mysql (locally or remotely). phpinfo()..

Help - make PHP pull a File List (dir/ls/etc) in a specifi.. - Complete n00b question yet again. Anyone know a way to make PHP pull a "file list" (know as dir in windows, ls in *nix, etc) for a specific directory, and have PHP print the results onto the page?

Question = how to make a user session expire? - i'm using the dreamweaver login. it uses php/mysql and user session. the problem i'm ecountering is that the sessions don't expire until you log out. how can i make the sessions expire in let's say 1 hour when there is no activity on the webpage? thank...

One query and problem LIMIT - Hi all, I have 2 tables: articles and categories articles table: ------------ articleid categoryid name categories table: --------------- categotyid name description I want to get the last entred 5 articles for each category with one quey: like..

multiple select but ......php/mysql/html - hello, Maybe someone can help me out with this one where i am stuck where i solve this in html or other code? html/php and mysql using in a html form: <tr> <td><?php echo"<font face=$b_fontface size=$b_fontsize&...
   Database Forums (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]