Jump to content
TNG Community
Jan Suhr

[SOLVED] Help needed, HREF link with mysql column variables

Recommended Posts

Jan Suhr

I am doing a simple mod to my site that will show who was born or died on todays date.

I got it working and get a list of people that is added to the topmenu.php file.

My problem is that I also want the names in the list to link to the getperson.php page for more information on that person.

This is the code I have
 

echo '<a href="getperson.php?personID=' . $row['personID'] . '&tree=' . $row['gedcom'] . '">' . $row['firstname'] . ' ' . $row['lastname'] . '<br>' . $row['birthdatetr'] . '</a></p>';

This will give me: Parse error: syntax error, unexpected ' ' (T_STRING), expecting ',' or ';' in your code 

What makes this even more frustrating is that exactly the same line of code works perfectly in Joomla that runs in parallell with my TNG site.

I have also tried different variants. If I run it without the HREF it will show the names, see screen shot.

This line is in a While loop and if I don't do that loop it will show correctly the last line with working link.

Below is the whole thing

$query = "SELECT * FROM `tng_people` WHERE DAYOFMONTH( birthdatetr ) =$daynumber AND MONTH( birthdatetr ) =$monthnumber AND YEAR(`deathdatetr`) != 0000 ORDER BY birthdatetr";
if($result = mysqli_query($connection, $query)){
	if(mysqli_num_rows($result) > 0) {
		while($row = mysqli_fetch_array($result)){
		echo "<p>";
		echo '<a href="getperson.php?personID=' . $row['personID'] . '&tree=' . $row['gedcom'] . '">' . $row['firstname'] . ' ' . $row['lastname'] . '<br>' . $row['birthdatetr'] . '</a></p>';
		}
	}
}

I'm not a PHP expert but I can normally get it done, this is above my skills.

Appreciate any help, thanks.

 

Screenshot 2020-03-25 10.41.55.png

Share this post


Link to post
Share on other sites
Jan Suhr

This was weird. 

When validating the code on a online service I found out that there was something wrong with the dots. Just deleting them and enter a new one solved the problem. Go figure...

Here is the complete code, I did some other changes when I tried to figure it out.

Below code is place in to your_template/topmenu.php
There are also a few lines at the top that connects to the database and specifies that day and month of today.

	$daynumber = date("d");
	$monthnumber = date("m");

And for the language in cust_text.php
 

$text['onThisDay'] = "On this day";
$text['bornOnThisDay'] = "Born";
$text['deadOnThisDay'] = "Deceased";



I will make this a mod later on.
 

			<?php
			echo "<h2>" . $text['onThisDay'] . "</h2>";
			echo "<h3>" . $text['bornOnThisDay'] . "</h3>";
			$connection =new mysqli($database_host, $database_username, $database_password, $database_name) or die("Connect failed to database");
			$query = "SELECT * FROM `tng_people` WHERE DAYOFMONTH( birthdatetr ) =$daynumber AND MONTH( birthdatetr ) =$monthnumber AND YEAR(`deathdatetr`) != 0000 ORDER BY birthdatetr";
			if($result = mysqli_query($connection, $query)){
				if(mysqli_num_rows($result) > 0) {
				while($row = mysqli_fetch_array($result)){
					$persId = $row['personID'];
					$treeId = $row['gedcom'];
					$persFirstName = $row['firstname'];
					$persLastName= $row['lastname'];
					$persBirthDate = $row['birthdatetr'];
					echo "<p>";
					echo "<a href=\"getperson.php?personID=" . $persId . "&tree=" . $treeId . "\" class=\"lightlink\">" . $persFirstName . ' ' . $persLastName . '<br>' . $persBirthDate . '</a></p>';
					}
				}
			}
			echo "<hr>";
			echo "<h3>" . $text['deadOnThisDay'] . "</h3>";
			$connection2 =new mysqli($database_host, $database_username, $database_password, $database_name) or die("Connect failed to database");
			$query2 = "SELECT * FROM `tng_people` WHERE DAYOFMONTH( deathdatetr ) =$daynumber AND MONTH( deathdatetr ) =$monthnumber ORDER BY deathdatetr";
			if($result2 = mysqli_query($connection2, $query2)){
				if(mysqli_num_rows($result2) > 0) {
				while($row2 = mysqli_fetch_array($result2)){
					$persId = $row2['personID'];
					$treeId = $row2['gedcom'];
					$persFirstName = $row2['firstname'];
					$persLastName= $row2['lastname'];
					$persDeathDate = $row2['deathdatetr'];
					echo "<p>";
					echo "<a href=\"getperson.php?personID=" . $persId . "&tree=" . $treeId . "\" class=\"lightlink\">" . $persFirstName . ' ' . $persLastName . '<br>' . $persDeathDate . '</a></p>';
					}
				}
			}

You can check it out on my TNG-site, see link below.

Share this post


Link to post
Share on other sites
manofmull

Jan

Very clever. I couldn't construct a mod if my life depended on it.

Just curious as to why you did this though, when TNG includes Dates & Anniversaries which gives these results

There's also a report that gives births for the current month

SELECT personID, lastname, firstname, birthdate, deathdate, YEAR(NOW())-YEAR(birthdatetr) AS Years, gedcom FROM tng_people WHERE MONTH(birthdatetr)=MONTH(NOW()) AND living=0 ORDER BY lastname, firstname, personID

dates.jpg

Share this post


Link to post
Share on other sites
Jan Suhr

My reason for doing this was primarily to get it to show up on my Joomla-site. I had that before when I used a Genealogy Joomla component that has this function as a module. This component is not available anymore and I have switched to TNG. I liked this function and was looking for a way to get it back when using TNG.

Since I then had the code I thought I could as easily have it in my TNG site as well. 

It is a bit different that your suggestion since it will always be there automatically and is easier for visitors to see rather than select a menu command, which by the way I have disabled.

 

 

Share this post


Link to post
Share on other sites
manofmull

Jan

Yes, I see from your image which looks good, great job.

I remember the days when mod creators would make them backward-compatible with older versions of TNG (I'm using TNG 11.1.2), but this no longer seems to be the case. I no longer have the time nor the will to upgrade to TNG 12

Share this post


Link to post
Share on other sites
Jan Suhr

I think that this mod would work with older versions

 

Share this post


Link to post
Share on other sites
Jan Suhr

You also see from the screen shot that I also have added a part that shows how many persons I have in the registry and when it was last updated.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×