Jump to content

Recommended Posts

http://www.further-flight.co.uk/previews/current.php

 

 

Question 1

I have in my database two columns that I'd like to use to produce links: url and date.  The url column has the address I'd like to use, and the date the text I'd like to use for the link.  I've seen a response to a similar question previously, and attempted to adapt this to my own code, but kept getting a blank page.  I'd like to keep all of the other data with the links too.

 

Question 2

Is there any way in which I can include the MySql column names on the pages where tables are produced of information from the database?

 

Current code:

 

<?php  
        // Connects to your Database  
        mysql_connect("******", "*******", "********") or die(mysql_error());  
        mysql_select_db("furtherfl") or die(mysql_error());  
        $data = mysql_query("SELECT * FROM race WHERE month='jul06' ORDER BY 'id'")  
        or die(mysql_error());  

        Print "<table cellpadding=2 width=95%>";  
        while($info = mysql_fetch_array( $data ))  
        
{  
        Print "<tr>"; 
        Print "<td>".$info['date'] . "</td> ";  
        Print "<td>".$info['race1'] . "</td> ";  
        Print "<td>".$info['race2'] . "</td> ";  
        Print "<td>".$info['race3'] . " </td>"; 
        Print "<td>".$info['previewer'] . " </td></tr>";  
        }  
        Print "</table>";  
        ?>   

Link to comment
https://forums.phpfreaks.com/topic/62249-auto-links-column-headings/
Share on other sites

Which column is the one containing the url? Just use format your data using date() (look at the PHP Manual) and put it inside an <a> element.

echo "<a href='".$info['url']."'>".date("m/d/y",$info['date'])."</a>";

Now, this'll only work if your date is a Unix timestamp (the number of seconds since the epoch, which I think is 01/01/1970).

I noticed this statement in your first mysql query: "WHERE month='jul06'"

It seems like you're adding data that you don't really need in there. Look into the MySQL manual and see how it handles dates. You can use that functionality to check the month if you decide on using SQL timestamps, which are just strings "mm-dd-yyyy". Alternatively, if you choose to stay with Unix timestamps, just use some of the date functions to generate a range for that month.

 

You can include the column names for the table header by either using MySQL functions or checking the keys of the array returned by mysql_fetch_array() with only associative indexes enabled.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.