|
Events - the 'pretty' version
The simple tabular list we showed on the previous page is a very basic arrangement. An obvious disadvantage is that if you have long event descriptions, your events list will take up a lot of page space. Suppose instead you wanted something like this:
Obviously there's more data being displayed (which means we need some extra fields in our database), and rows are alternately coloured, but the biggest difference is that where we have a lot of information about an event we have a clickable 'more information' link. So let's see how that was done.
Somehow we need to construct a link that's specific to each data record where extra information exists, and then we need that link to go to a page that displays a single specific record from our database. Sounds easy enough - and it is. One of the fields in our database is the unique ID for a record, so if we could pass that information along to another page ....
...
while ($myrow = mysql_fetch_array($result)) // loop through all results
{ ...
echo "<td>
if ($myrow['ev_long']) // ev_long is not null
{
echo "<a href='showmore.php?id='". $myrow['id']. "'>more info</a>"; // link to a new page
}
else
{
echo " ";
}
echo "</td></tr>";
...
}
// loop done
...
And for the page named showmore.php, getting the right database record is simple as you already know which record you want. As it has been passed from a link, not a form, we use the GET method for finding the value of the parameter passed on.
$id = $_GET['id']
.....
$query = "SELECT * from $db_table WHERE id='$id' ";
.... // display data however you choose
....
That's all
As you can see, an 'upcoming events' system for your site that automatically shows only future events, in the correct date sequence, is some fairly simple coding once you understand how to retrieve information from your database.
If you need 'all' the source code for this example, view & copy/paste this.
        
Average Rating: 6 out of 10 from 2 voters.
« previous
|