?
Solved

If Statement for sepecifc link to PDF

Posted on 2007-10-01
5
Medium Priority
?
272 Views
Last Modified: 2013-12-13
I am still new to PHP and was wondering how i would put in a specifc link to a pdf file on my page to show up under one set of data but not  the other.

<?
                          if (mysql_fetch_row(mysql_query("SELECT * from psh_communities WHERE status='Current' and area='San Diego'")) == "" || !$result) {
                              print "<p>Coming Soon</p><p>&nbsp;</p>";
                        } else {
                        print "<table border='0' cellspacing='0' cellpadding='5'>";
                              while($row = mysql_fetch_row($result)) {
                                    print "<tr><td valign='top' align='center'><a href='community.php?ID=" . $row[0] . "'><img src='../images/browse/logos/" . $row[0] . "-TH.jpg' alt='" . $row[1] . "' border='0' /></a></td>";
                                    print "<td valign='top'><p><span class='comm-header-exception'>" . $row[1] . "</span><br />";
                                    print $row[5] . "<br />";
                                    print "<a href='community.php?ID=" . $row[0] . "'>View Details</a></p>";
                                    print "</td></tr>";
                              }
                                                                  print "</table>";
                        }
                    ?>

Under view details i want to put another link for Self-Qual Form and the location is http://homes.pacificscene.com/browse/selfqualform/ and i just want to add it as hyperlink for community.php?ID=43 and no others.

Could someone give me a hand on how to do this?
0
Comment
Question by:Jiggens
5 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 19994086
...
print $row[5] . "<br />";
print "<a href='community.php?ID=" . $row[0] . "'>View Details</a>"
if ($row[0] == 43) {
  print " <a href='http://homes.pacificscene.com/browse/selfqualform/'>Self-Qual Form</a>";
}
print "</p>";
print "</td></tr>";
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 19994107
if ($row[0]=='43') {
  print "<a href='test.pdf'>PDF Link</a>";
}

Place this wherever you want the link.
0
 
LVL 1

Expert Comment

by:Discomonkey
ID: 19994221
Jiggens,

What I would prescribe is that you loop through your dataset and perform a test condition inside that loop.  See below:

// Prepare your query
$qry = "SELECT * from psh_communities WHERE status='Current' and area='San Diego'";

// Perform query
$result = mysql_query($qry) or die("this query is no good, here's why: " . mysql_error());

// Loop through query result
while ($row = mysql_fetch_array($result)) {
          if($row['_CRITERIA_'] != TRUE){
print "<p>Coming Soon</p><p>&nbsp;</p>";
                        } else {
                        print "<table border='0' cellspacing='0' cellpadding='5'>";
                              while($row = mysql_fetch_row($result)) {
                                    print "<tr><td valign='top' align='center'><a href='community.php?ID=" . $row[0] . "'><img src='../images/browse/logos/" . $row[0] . "-TH.jpg' alt='" . $row[1] . "' border='0' /></a></td>";
                                    print "<td valign='top'><p><span class='comm-header-exception'>" . $row[1] . "</span><br />";
                                    print $row[5] . "<br />";
                                    print "<a href='community.php?ID=" . $row[0] . "'>View Details</a></p>";
                                    print "</td></tr>";
                              }
                                                                  print "</table>";
                        }


where _CRITERIA_ is whatever piece of information that your data has that you need to test against.

Does this help?

ps, as a long time PHP developer, I suggest you reference your return data by name instead of index.  mysql_fetch_array() will generate both index and a name reference per column in each row.    so:

TABLE
ID      NAME         PHONE
1       chris            12345
2       bob              67890

$res = mysql_query('select * from TABLE');

mysql_fetch_array($res) will return something like array([0]=>1, ['ID']=>1, [1] => 'chris', ['NAME'] => 'chris', [2]=>'12345', ['PHONE']=>'12345').  Does this make sense?
0
 
LVL 1

Expert Comment

by:Discomonkey
ID: 19994301
Jiggens,

i don't think I correctly answered your question.   Also I didn't really review your code beyond the if / else statement, and so what I posed doesn't really make sense.

What I think you want to do is output a set of data, but only show a particular link for some parts of that data.  Is that correct?
0
 
LVL 6

Expert Comment

by:ebosscher
ID: 19995308
Jiggens,

I'm curious what you mean by "I want to print it if the link is ID=43", do you mean you want it on the form if that is the requesting URL, or you want it on the form if the generated link is ID=43?  if it's when the gentrated link is ID=43 then TerryAtOpus would appear to have the correct answer, and the code is already in the right place.  

If the link needs to be put there when the requesting ID=43 in the query string then you'll need to do the following:

print "<a href='community.php?ID=" . $row[0] . "'>View Details</a><br/>";
if( $_GET['ID'] == '43' )
{
    print " <a href='http://homes.pacificscene.com/browse/selfqualform/'>Self-Qual Form</a>";
}
print "</p>";
print "</td></tr>";
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question