|
Posted by Hilarion on 11/16/05 14:04
> what im looking to do is hve a page grab data from a DB
> would like to pull the data out from the DB
> the data base contains
> id title url text startdate experation
>
> would like the lookup to grab the data
> and paste it into the table..DB will have multiple entry's
> the experation is just a number like 7-14 so it is days that it runs
>
> would like to have the data outputed like
>
> <a href=http://$url>$title</a>
> $text
> Ends $startdate + $experation (like 11/15/2005 + 14 = 11/29/2005)
> would also need an if statement so if the startdate + experation is
> expired dont show this ad...
>
> hope this helps thoughts are crossing...
> annie
>
>
> <?php
> $result=mysql_query("select * from text_ads ORDER BY `date` DESC");
> while ($row = mysql_fetch_array($result)) {
> $title = $row["title"];
> $url = $row["url"];
> $text= $row["text"];
> $startdate = $row["date"];
> $experation = $row["expiration"];
> echo
> "<table border='1' width='125'>".
> "<tr><td><a class=link href=\"$url\" target='_balnk'>$title</a>
> </td></tr>" .
> "<tr><td><div align =center>$text</div></td></tr>" .
> "<tr><td><div align =center>$experation</div></td><tr>" .
> "</table>";
> }
> ?>
<?php
error_reporting( E_ALL );
// You'll have to establish a connection to MySQL server and select
// the database you'll work with before using "mysql_query"
// function. Place that code here.
$result = mysql_query(
'SELECT ' .
' url, title, text, date, ' .
' ADDDATE( date, INTERVAL expiration DAY ) AS expiration_date ' .
'FROM text_ads ' .
'WHERE ADDDATE( date, INTERVAL expiration DAY ) >= CURRENT_DATE() ' .
'ORDER BY date DESC'
);
if ($result === FALSE)
{
die( 'Error executing query: ' . mysql_error() );
}
?>
<table border="1" width="125">
<tbody>
<?php
while ($row = mysql_fetch_array($result))
{
?>
<tr>
<td><a class="link" href="<?php
echo htmlspecialchars( $row['url'] );
?>" target="_blank"><?php
echo htmlspecialchars( $row['title'] );
?></a></td>
</tr>
<tr>
<td align="center"><?php
echo htmlspecialchars( $row['text'] );
?></td>
</tr>
<tr>
<td align="center"><?php
echo $row['expiration_date'];
?></td>
</tr>
}
?>
</tbody>
</table>
Hilarion
Navigation:
[Reply to this message]
|