Page 1 of 1

Creating hyperlinks from MySQL dB

Posted: Wed May 14, 2008 5:56 am
by kdidymus
One last question I'm hoping somebody can help with.

This is my PHP code for my "results" page:

Code: Select all

<?php
/* Program: display.php
 * Desc:    Displays all details of selected individual.
 */
?>
<html>
<head><title>Results</title></head>
<body>
<?php
include_once("*******.inc");
  $cxn = mysql_connect($host,$user,$password)
         or die ("couldn't connect to server");
  mysql_select_db($database);
  $urn=$_GET['urn'];  //urn passed by hyperlink
  $query = "SELECT * FROM tree WHERE urn='$urn'";
  $result = mysql_query($query)
            or die ("Couldn't execute query.");
 
  /* Display results in a table */
  $urn = ucfirst($urn);
  while($row = mysql_fetch_assoc($result))
  {
     extract($row);
  echo "<font face='Arial' size='3'><b>$surname, $forename $middlenames</font></b>";
  echo "<table cellspacing='0'>";
  echo "<tr><td colspan='3'><hr /></td></tr>";
     echo " <tr>\n
            <td  valign='top'><font face='Arial' size='1'><b>URN:</font></b></td><td  valign='top'><font face='Arial' size='1'>$urn</font></td>\n
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>SURNAME:</font></b></td><td  valign='top'><font face='Arial' size='1'>$surname</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>FORENAME(S):</font></b></td><td><font face='Arial' size='1'>$forename $middlenames</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>DATE OF BIRTH:</font></b></td><td><font face='Arial' size='1'>$dateofbirth</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>PLACE OF BIRTH:</font></b></td><td><font face='Arial' size='1'>$placeofbirth</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>MOTHER:</font></b></td><td><font face='Arial' size='1'>$mother</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>FATHER:</font></b></td><td><font face='Arial' size='1'>$father</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>SIBLINGS:</font></b></td><td><font face='Arial' size='1'>$sibling1</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling2</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling3</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling4</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling5</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling6</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling7</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling8</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1' bgcolor='#CCFFCC'>$sibling9</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$sibling10</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>CHRISTENING DATE:</font></b></td><td><font face='Arial' size='1'>$christeningdate</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>CHRISTENING PLACE:</font></b></td><td><font face='Arial' size='1'>$christeningplace</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>SPOUSE 1:</font></b></td><td><font face='Arial' size='1'>$spouse1</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>MARRIAGE DATE:</font></b></td><td><font face='Arial' size='1'>$spouse1marriagedate</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>MARRIAGE PLACE:</font></b></td><td><font face='Arial' size='1'>$spouse1marriageplace</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>CHILDREN:</font></b></td><td><font face='Arial' size='1'>$spouse1child1</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1' bgcolor='#CCFFCC'>$spouse1child2</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1' bgcolor='#CCFFCC'>$spouse1child3</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child4</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child5</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child6</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child7</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child8</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child9</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse1child10</td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>SPOUSE 2:</font></b></td><td><font face='Arial' size='1'>$spouse2</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>MARRIAGE DATE:</font></b></td><td><font face='Arial' size='1'>$spouse2marriagedate</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>MARRIAGE PLACE:</font></b></td><td><font face='Arial' size='1'>$spouse2marriageplace</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>CHILDREN:</font></b></td><td><font face='Arial' size='1'>$spouse2child1</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child2</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child3</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child4</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child5</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child6</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child7</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child8</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child9</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td></td><td><font face='Arial' size='1'>$spouse2child10</td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>OCCUPATION:</font></b></td><td><font face='Arial' size='1'>$occupation</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>DATE OF DEATH:</font></b></td><td><font face='Arial' size='1'>$dateofdeath</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>PLACE OF DEATH:</font></b></td><td><font face='Arial' size='1'>$placeofdeath</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>CAUSE OF DEATH:</font></b></td><td><font face='Arial' size='1'>$causeofdeath</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>NOTES:</font></b></td><td><font face='Arial' size='1'>$notes</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>CERTIFICATES:</font></b></td><td><font face='Arial' size='1'>$certificates</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>CENSUS:</font></b></td><td><font face='Arial' size='1'>$census</font></td>\n</tr>
        <tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>PHOTOGRAPHS:</font></b></td><td><font face='Arial' size='1'>$photographs</font></td>\n</tr>
        <tr valign='top'><td><font face='Arial' size='1'><b>SCRAPBOOK:</font></b></td><td><font face='Arial' size='1'>$scrapbook</font></td>\n</tr>
        </tr>\n";
     echo "<tr><td colspan='3'><hr /></td></tr>\n";
  }
  echo "</table>\n";
?>
</body></html>
What I want to do is insert hyperlinks for various ancestors.

Take a look at http://www.didymus.org.uk/display.php?urn=583

Let's take Edwin's mother as an example.

There are two columns for her in my MySQL database. One is $mother which gives her full name and the other is $motherurn which stores her Unique Reference Number (URN).

I want the results page to show her name as a hyperlink. When the user clicks on it, they're taken to http://www.didymus.org.uk/display.php?urn= (plus the reference number stored in $motherurn).

Thing is, I don't know how to do this. I want to do it this way to avoid having to produce a separate PHP page for EACH ancestor.

HAYLP! PLEASE!

Kris.

Re: Creating hyperlinks from MySQL dB

Posted: Wed May 14, 2008 6:11 am
by N1gel
I think this should do it.

Code: Select all

 
        echo "<tr bgcolor='#CCFFCC' valign='top'><td><font face='Arial' size='1'><b>MOTHER:</font></b></td><td><font face='Arial' size='1'><a href='http://www.didymus.org.uk/display.php?urn=$motherurn' >$mother</a></font></td>\n</tr>";
 
I'd also look at using some CSS.

Hope this helps :D

Nigel

Re: Creating hyperlinks from MySQL dB

Posted: Wed May 14, 2008 6:35 am
by kdidymus
Fantastic. It worked like a dream. Thank you.

I've used CSS before but could you possibly help with an idiot's guide for implementing it for my PHP page?

Obviously I need the header (Arial, size 3, bold), the basic text (Arial, size 1) and an enboldened version for the column tags (Arial, size 1, bold). I could also use some help with specifying the alternating row colours (currenty #CCFFCC).

Like I said, I'm going to need this explained fully as I have no idea what I'm doing in PHP.

Many, MANY thanks.

Kris.

Re: Creating hyperlinks from MySQL dB

Posted: Wed May 14, 2008 6:50 am
by onion2k
CSS is nothing to do with PHP really. It's a language for styling things in the user's browser. I suggest you find a tutorial and work through it because it's a very big topic ... far too big to explain in a forum post.

Re: Creating hyperlinks from MySQL dB

Posted: Wed May 14, 2008 9:11 am
by aceconcepts
Here's a good place to start http://www.w3.org/Style/CSS/learning

Re: Creating hyperlinks from MySQL dB

Posted: Thu May 15, 2008 5:24 am
by kdidymus
Thank you all for your advice. I looked in to using CSS but found an easier way. I've used $strings in the PHP code to automatically generate repeatedly used data throughout...

Code: Select all

<?php
/* Program: display.php
 * Desc:    Displays all details of selected individual.
 */
?>
<html>
<head><title>Results</title></head>
<body>
<?php
include_once("*******.inc");
  $cxn = mysql_connect($host,$user,$password)
         or die ("couldn't connect to server");
  mysql_select_db($database);
  $urn=$_GET['urn'];  //urn passed by hyperlink
  $query = "SELECT * FROM tree WHERE urn='$urn'";
  $result = mysql_query($query)
            or die ("Couldn't execute query.");
  $link = "http://www.didymus.org.uk/display.php?urn=";
  $rowht = "valign='top'";
  $rowcl = "bgcolor='#CCFFCC' valign='top'";
  $text = "font face='Arial' size='1'";
  $hltext = "font face='Arial' size='1' color='#000000'";
 
  /* Display results in a table */
  $urn = ucfirst($urn);
  while($row = mysql_fetch_assoc($result))
  {
     extract($row);
  echo "<font face='Arial' size='3'><b>$surname, $forename $middlenames</font></b>";
  echo "<table cellspacing='0' width='490'>";
  echo "<tr><td colspan='3'><hr /></td></tr>";
     echo " <tr>\n
            <td $rowht><$text><b>URN:</font></b></td><td><$text>$urn</font></td>\n
        <tr $rowcl><td><$text><b>SURNAME:</font></b></td><td><$text>$surname</font></td>\n</tr>
        <tr $rowht><td><$text><b>FORENAME(S):</font></b></td><td><$text>$forename $middlenames</font></td>\n</tr>
        <tr $rowcl><td><$text><b>DATE OF BIRTH:</font></b></td><td><$text>$dateofbirth</font></td>\n</tr>
        <tr $rowht><td><$text><b>PLACE OF BIRTH:</font></b></td><td><$text>$placeofbirth</font></td>\n</tr>
        <tr $rowcl><td><$text><b>MOTHER:</font></b></td><td><a href='$link$motherurn'><$hltext>$mother</a>
</font></td>\n</tr>
        <tr $rowht><td><$text><b>FATHER:</font></b></td><td><a href='$link$fatherurn'><$hltext>$father</a></font></td>\n</tr>
        <tr $rowcl><td><$text><b>SIBLINGS:</font></b></td><td><a href='$link$sibling1urn'><$hltext>$sibling1</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling2urn'><$hltext>$sibling2</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling3urn'><$hltext>$sibling3</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling4urn'><$hltext>$sibling4</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling5urn'><$hltext>$sibling5</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling6urn'><$hltext>$sibling6</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling7urn'><$hltext>$sibling7</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling8urn'><$hltext>$sibling8</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling9urn'><$hltext>$sibling9</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$sibling10urn'><$hltext>$sibling10</a></font></td>\n</tr>
        <tr $rowht><td><$text><b>CHRISTENING DATE:</font></b></td><td><$text>$christeningdate</font></td>\n</tr>
        <tr $rowcl><td><$text><b>CHRISTENING PLACE:</font></b></td><td><$text>$christeningplace</font></td>\n</tr>
        <tr $rowht><td><$text><b>SPOUSE 1:</font></b></td><td><a href='$link$spouse1urn'><$hltext>$spouse1</a></font></td>\n</tr>
        <tr $rowcl><td><$text><b>MARRIAGE DATE:</font></b></td><td><$text>$spouse1marriagedate</font></td>\n</tr>
        <tr $rowht><td><$text><b>MARRIAGE PLACE:</font></b></td><td><$text>$spouse1marriageplace</font></td>\n</tr>
        <tr $rowcl><td><$text><b>CHILDREN:</font></b></td><td><a href='$link$spouse1child1urn'><$hltext>$spouse1child1</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child2urn'><$hltext>$spouse1child2</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child3urn'><$hltext>$spouse1child3</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child4urn'><$hltext>$spouse1child4</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child5urn'><$hltext>$spouse1child5</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child6urn'><$hltext>$spouse1child6</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child7urn'><$hltext>$spouse1child7</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child8urn'><$hltext>$spouse1child8</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child9urn'><$hltext>$spouse1child9</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse1child10urn'><$hltext>$spouse1child10</a></font></td>\n</tr>
        <tr $rowht><td><$text><b>SPOUSE 2:</font></b></td><td><a href='$link$spouse2urn'><$hltext>$spouse2</a></font></td>\n</tr>
        <tr $rowcl><td><$text><b>MARRIAGE DATE:</font></b></td><td><$text>$spouse2marriagedate</font></td>\n</tr>
        <tr $rowht><td><$text><b>MARRIAGE PLACE:</font></b></td><td><$text>$spouse2marriageplace</font></td>\n</tr>
        <tr $rowcl><td><$text><b>CHILDREN:</font></b></td><td><a href='$link$spouse2child1urn'><$hltext>$spouse2child1</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child2urn'><$hltext>$spouse2child2</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child3urn'><$hltext>$spouse2child3</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child4urn'><$hltext>$spouse2child4</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child5urn'><$hltext>$spouse2child5</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child6urn'><$hltext>$spouse2child6</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child7urn'><$hltext>$spouse2child7</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child8urn'><$hltext>$spouse2child8</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child9urn'><$hltext>$spouse2child9</a></font></td>\n</tr>
        <tr $rowcl><td></td><td><a href='$link$spouse2child10urn'><$hltext>$spouse2child10</a></font></td>\n</tr>
        <tr $rowht><td><$text><b>OCCUPATION:</font></b></td><td><$text>$occupation</font></td>\n</tr>
        <tr $rowcl><td><$text><b>DATE OF DEATH:</font></b></td><td><$text>$dateofdeath</font></td>\n</tr>
        <tr $rowht><td><$text><b>PLACE OF DEATH:</font></b></td><td><$text>$placeofdeath</font></td>\n</tr>
        <tr $rowcl><td><$text><b>CAUSE OF DEATH:</font></b></td><td><$text>$causeofdeath</font></td>\n</tr>
        <tr $rowht><td><$text><b>NOTES:</font></b></td><td><$text>$notes</font></td>\n</tr>
        <tr $rowcl><td><$text><b>CERTIFICATES:</font></b></td><td><$text>$certificates</font></td>\n</tr>
        <tr $rowht><td><$text><b>CENSUS:</font></b></td><td><$text>$census</font></td>\n</tr>
        <tr $rowcl><td><$text><b>PHOTOGRAPHS:</font></b></td><td><$text>$photographs</font></td>\n</tr>
        <tr $rowht><td><$text><b>SCRAPBOOK:</font></b></td><td><$text>$scrapbook</font></td>\n</tr>
        </tr>\n";
     echo "<tr><td colspan='3'><hr /></td></tr>\n";
  }
  echo "</table>\n";
?>
</body></html>
This seems to work fine and is also shorter than using style tags in that most of the html is stored in the $strings.

I'm on my way to completing my website. Thank you all again.

Kris.

Re: Creating hyperlinks from MySQL dB

Posted: Thu May 15, 2008 5:36 am
by aceconcepts
CSS actually adopts the same concept - it simply allows more flexibility.

e.g.

Code: Select all

 
<style type="text/css">
.h1Text{ font-family:Arial, Verdana, Helvetica, Sans-serif; font-size:12px; color:black; }
</style>
 
You would reference this by:

Code: Select all

 
<td class="h1Text">