Link to home
Start Free TrialLog in
Avatar of Jiggens
Jiggens

asked on

If Statement for sepecifc link to PDF

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?
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if ($row[0]=='43') {
  print "<a href='test.pdf'>PDF Link</a>";
}

Place this wherever you want the link.
Avatar of Discomonkey
Discomonkey

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?
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?
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>";