• Welcome to BirdForum, the internet's largest birding community with thousands of members from all over the world. The forums are dedicated to wild birds, birding, binoculars and equipment and all that goes with it.

    Please register for an account to take part in the discussions in the forum, post your pictures in the gallery and more.
ZEISS DTI thermal imaging cameras. For more discoveries at night, and during the day.

PHP help ereusted (1 Viewer)

pigsonthewing

Well-known member
PHP help requested

I'm finally learning to code in PHP, to make my work managing a bird club website easier. I plan to store and handle bird names as five-letter BTO codes.

I'm looking for some PHP code which will return the common and/ or scientific name of a bird, if given the code (e.g. "Black Redstart" or "Phoenicurus ochruros" for "BLARE") - presumably, by doing a database lookup, so I also need the database!

Can anyone help, please?
 
Last edited:
pigsonthewing said:
I'm finally learning to code in PHP, to make my work managing a bird club website easier. I plan to store and handle bird names as five-letter BTO codes.

I'm looking for some PHP code which will return the common and/ or scientific name of a bird, if given the code (e.g. "Black Redstart" or "Phoenicurus ochruros" for "BLARE") - presumably, by doing a database lookup, so I also need the database!

Can anyone help, please?

You will probably want to use MySQL for your db. Most likely if your host has PHP, they will have MySQL. Here is the function I use for my connection to my database:

<?php
function db_connect()
{
$link=@mysql_pconnect("localhost", "USERNAME", "PASSWORD");
if ($link && mysql_select_db("DBNAME"))
return ($link);
return(FALSE);
}
?>


Create a user in the database either through a SQL query (was it GRANT or something like that?) or through a web GUI like phpMyAdmin and give the user appropriate rights. I would create two users - a read user and a write user.

Then you might call the function like so:

<?php

db_connect() or exit("There was a problem connecting to the database.");
$result=mysql_query("SELECT * FROM birdlist WHERE codename = 'blare'");
while ($row=mysql_fetch_array($result))
{
echo "<P>";
echo $row["commonname"];
echo "<BR>";
echo $row["latinname"];
echo "<BR>";
echo $row["codename"];
echo "</P>";

}
?>


Double check my sql syntax, it's been a while.

I would create the table as three columns (commonname, latinname, codename). If you don't want to create them manually via GUI (e.g., phpMyAdmin), you can import the db from a text file, but that can get tricky depending on where you're getting the info from. You could also write a million insert statements, but that would be laborious.

I hope that helps you get started!
 
Warning! This thread is more than 18 years ago old.
It's likely that no further discussion is required, in which case we recommend starting a new thread. If however you feel your response is required you can still do so.

Users who are viewing this thread

Back
Top