Forum Moderators: coopster

Message Too Old, No Replies

Adding date to results

How do I add the date

         

Impaired Person

8:22 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



I have a mysql database with links to files which output as links. I have added a Table called "Date" for the date the file was last indexed.

what I want to do is add a table to output the DATE without it being included in the link.

$counter = $range + 1;
while($row = mysql_fetch_row($result)) {
$fullURL = "ftp://".$row[2].":".$row[3]."@".$row[1].":".$row[4].$row[0];
$linkURL = htmlentities(str_replace(" ", "%20", $fullURL));
echo "$counter. <a href=$linkURL>$fullURL</a><br>";

How do I add the table to the end of the file to generate dynamically with the results?

Thank You,
disabled person

jatar_k

9:23 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Impaired Person,

did you just want to output it onto the page? I ma not really sure what you want to do.

Have you got the date included in the sql statement already? Or, if not, maybe give us a look at the query, add it to that and then you can just add an extra element to your ech statement.

Impaired Person

10:01 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



Here is what i have:
$query = "SELECT files.filename, ftps.hostname, ftps.username, ftps.password, ftps.port FROM files INNER JOIN ftps ON ftps.Code=files.Code WHERE files.Filename like '%$search%'";
$result = mysql_query($query);
$numFound = mysql_num_rows($result);

$query = "SELECT files.filename, ftps.hostname, ftps.username, ftps.password, ftps.port FROM files INNER JOIN ftps ON ftps.Code=files.Code WHERE files.Filename like '%$search%' LIMIT $range, $ResultsPerPage";
$result = mysql_query($query);

$counter = $range + 1;
while($row = mysql_fetch_row($result)) {
$fullURL = "ftp://".$row[2].":".$row[3]."@".$row.":".$row[4].$row[0];
$linkURL = htmlentities(str_replace(" ", "%20", $fullURL));
echo "$counter. <a href=$linkURL>$fullURL</a><br>";
$counter++;
}

if ($numFound) {
echo "<br><br><p align=center>";
if ($range!=0) echo "<a href=?rn=".($range-50)."&search=$search><< PREV $ResultsPerPage</a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
if (($counter-1)!=$numFound) echo "<a href=?rn=".($range+50)."&search=$search>NEXT $ResultsPerPage >></a>";
echo "</p>";
echo "<br><HR><b>Total number of matches found: $numFound</b>";
} else {
echo "<br><br><HR><b>Sorry, your search returned no results.</b>";
}

}
?>

I would mlike a table to the right of the results that says when it was last indexed. can ya help?

Thank You
Disabled

[1][edited by: jatar_k at 12:02 am (utc) on Dec. 31, 2003]
[edit reason] no personal urls thanks [/edit]

coopster

11:55 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So you have created a new table/file named
date
(this is not a name you should use for a table or column [mysql.com], by the way) which probably has the
Code
field as the PRIMARY KEY. First off, why not just ALTER [mysql.com] your current table to add the new field, date_last_indexed? Then write a one-time script to populate the field with the correct date for each file...? Just curious.

Otherwise, you'll probably want to LEFT JOIN the

date_table
table in your SQL statement and handle the output accordingly:

$query = "SELECT
files.filename,
ftps.hostname,
ftps.username,
ftps.password,
ftps.port,
date_table.date_last_indexed
FROM files
INNER JOIN ftps ON ftps.Code=files.Code
LEFT JOIN date_table ON files.Code=date_table.Code
WHERE files.Filename like '%$search%' LIMIT $range, $ResultsPerPage";

Then while you echo out your line-by-line information, format accordingly:

echo "$counter. <a href=$linkURL>$fullURL</a> " . $row[6] . "<br>";

Impaired Person

2:14 am on Jan 5, 2004 (gmt 0)

10+ Year Member



Ok...sorry for delay. And THANK YOU for your response.

I have the table 'ftps' with the column 'Indexed'. It is in the timestamp form. I have got it to echo the results on the page to display the last indexing but it reads like so...:

"" 1. *************/sur/drivers/modem/at&t/Lucent modem driver for Compaq laptops.zip
20040104190522 -- Last Indexed
2. *************/sur/drivers/modem/at&t/Lucent V.90 Modem Drivers.exe
20040104190522 -- Last Indexed
3. *************/sur/drivers/modem/at&t/lucent-v92.zip
20040104190522 -- Last Indexed
4. *************/sur/drivers/modem/Lucent
20040104190522 -- Last Indexed """"

and this is what produces it....
echo "$counter. <a href=$linkURL>$fullURL</a><br>". $row[5] ." -- Last Indexed<br>";

WHAT AND WHERE do I put code to make it more readable?

I just cant get it right.

Thanks for any code you might add into it for me.

Disabled

coopster

3:25 pm on Jan 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>WHAT AND WHERE do I put code to make it more readable?

I'm assuming you want to format the timestamp? You can format it as you pull it from MySQL [mysql.com] or you can format it using the PHP date [php.net] function. Personally, I would use the MySQL DATE_FORMAT() [mysql.com] function as it is being pulled from the database:


$query = "SELECT
files.filename,
ftps.hostname,
ftps.username,
ftps.password,
ftps.port,
DATE_FORMAT(ftps.Indexed, '%W %M %Y') AS date_formatted
FROM ...

You will want to change the formatting to your liking -- coopster