movieprodw
asked on
PHP if not in db echo
Hello,
I am making a website for a magazine company and they have featured articles they publish every month.
They have been around for 5 years so there are a lot of articles that need to be inserted into the db.
What I would like to do is make it so that it will count from the first month ie '03/2005' to the current month ie 'MM/YYYY', create an array ie 03/2005, 04/2005, 05/2005 and check if those are in the db, if not then echo a list of the ones not in the db
It sounds really complex to me but I am assuming this is cake for some of you guys!
I would appreciate any help.
Here is the code I am using to currently echo the data.
<?php
$result = mysql_query("SELECT * FROM articles ORDER BY SUBSTRING(date,4) DESC, SUBSTRING(date, 1, 2) DESC")
or die(mysql_error());
echo "<table border='0' width='100%'>";
echo "<tr> <td><strong>Date</strong>< /td> <td><strong>Title</strong> </td> </tr>";
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td width='60px'>";
echo $row['date'];
echo "</td><td>";
echo $row['title'];
echo "</td></tr>";
}
echo "</table>";
?>
I am making a website for a magazine company and they have featured articles they publish every month.
They have been around for 5 years so there are a lot of articles that need to be inserted into the db.
What I would like to do is make it so that it will count from the first month ie '03/2005' to the current month ie 'MM/YYYY', create an array ie 03/2005, 04/2005, 05/2005 and check if those are in the db, if not then echo a list of the ones not in the db
It sounds really complex to me but I am assuming this is cake for some of you guys!
I would appreciate any help.
Here is the code I am using to currently echo the data.
<?php
$result = mysql_query("SELECT * FROM articles ORDER BY SUBSTRING(date,4) DESC, SUBSTRING(date, 1, 2) DESC")
or die(mysql_error());
echo "<table border='0' width='100%'>";
echo "<tr> <td><strong>Date</strong><
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td width='60px'>";
echo $row['date'];
echo "</td><td>";
echo $row['title'];
echo "</td></tr>";
}
echo "</table>";
?>
could you pl post the table structure of articles table for further help.
ASKER
hello njovin
It did not error but also did not output anything but
'article title or whateverarticle title or whatever '
karunamoorthy
the table structure is
[id] [date] [title]
1 mm/yyyy 'car article'
It did not error but also did not output anything but
'article title or whateverarticle title or whatever '
karunamoorthy
the table structure is
[id] [date] [title]
1 mm/yyyy 'car article'
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Awesome!
Thank you so much
Thank you so much
j = month
Open in new window