I have a bad habit of over-explaining myself (in what I say and my coding), so I want to apologize for that ahead of time.
OK, here is what I am working with. I have 4 tables: news, recipes, components, and finished product. When I add a new recipe, component, or finished product to their table, I timestamp them with the date they are entered (called datecreated) or modified (called datemodified). When I make a news post, I timestamp it also for the day I made it (called dateid). Both time stamps are the same format.
I am wanting to make it so when I make a news posts, it checks the other 3 tables for entires created or modified on that day, and prints them at the end of the news post. I am going to make a news post each day and I have the news post set up in a loop.
Here is the problem. I made a news post for Janurary 5th. When I looked at the page, it displays the news posts, as well as the entries created that day. I then made a news post for Janurary 6th. Well, it is not looping and displaying the 6th’s news posts below the 5th’s.
Here is the page for reference of what it is doing: [URL=http://www.amyandjessica.com/salvage/index3.php]http://www.amyandjessica.com/salvage/index3.php
Been staring at my coding for almost 2 days, and I can’t find it. Here is the code:
[code=php]<?php
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM news”;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
//starting news loop
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$date = $newArray[‘date’];
$submittedby = $newArray[‘submittedby’];
$post = $newArray[‘post’];
$dateid = $newArray[‘dateid’];
echo ‘<table width=”700″>’;
echo ‘<tr>’;
echo ‘ <td bgcolor=”#C09C54″><strong><font color=”FFFFFFF”><div align=”center”>’.$date.'</div></font></strong></td>’;
echo ‘</tr>’;
echo ‘<tr>’;
echo ‘ <td><font size=”2″>’;
echo ‘ <br><hr align=”center” width=”50%”>’.$post.'<hr align=”center” width=”50%”></font></td>’;
echo ‘</tr>’;
echo ‘<tr>’;
echo ‘<td><font size=”2″>’;
//checking 1st table for new entries and printing if any
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM salvage where datecreated = ‘$dateid’ “;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
if ($number_of_rows >0)
{
echo ‘<strong>New Base Items :: </strong>’;
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$name = $newArray[‘name’];
echo ‘<a href=”salvage.php?id=’.$id.'”>’.$name.'</a> <strong>::</strong> ‘;
}
}
echo ‘<p>’;
}
//checking 2nd table for new entries and printing if any
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM recipies where datecreated = ‘$dateid’ “;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
if ($number_of_rows >0)
{
echo ‘<strong>New Recipes :: </strong>’;
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$name = $newArray[‘name’];
echo ‘<a href=”recipes.php?id=’.$id.'”>’.$name.'</a> <strong>::</strong> ‘;
}
}
echo ‘<p>’;
}
//checking 3rd table for new entries and printing if any
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM drops where datecreated = ‘$dateid’ “;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
if ($number_of_rows >0)
{
echo ‘<strong>New Salvage Drops :: </strong>’;
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$name = $newArray[‘name’];
echo ‘<a href=”drops.php?id=’.$id.'”>’.$name.'</a> <strong>::</strong> ‘;
}
}
echo ‘<p>’;
}
//checking 1st table for modified entries and printing if any
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM salvage where datemodified = ‘$dateid’ “;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
if ($number_of_rows >0)
{
echo ‘<strong>Updated Base Items :: </strong>’;
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$name = $newArray[‘name’];
echo ‘<a href=”salvage.php?id=’.$id.'”>’.$name.'</a> <strong>::</strong> ‘;
}
}
echo ‘<p>’;
}
//checking 2nd table for modified entries and printing if any
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM recipies where datemodified = ‘$dateid’ “;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
if ($number_of_rows >0)
{
echo ‘<strong>Updated Recipes :: </strong>’;
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$name = $newArray[‘name’];
echo ‘<a href=”recipes.php?id=’.$id.'”>’.$name.'</a> <strong>::</strong> ‘;
}
}
echo ‘<p>’;
}
//checking 3rd table for modified entries and printing if any
//connecting to server
$dbh = mysql_connect (“localhost”, “username”, “password”) or die (‘I cannot connect to the server because: ‘ . mysql_error());
//connecting to database
mysql_select_db (“database”, $dbh) or die (‘I can not connect to the database because: ‘ . mysql_error());
//retriving data
$sql = “SELECT * FROM drops where datemodified = ‘$dateid’ “;
$result = mysql_query($sql, $dbh) or die(‘Could not retrive data from table because: ‘ . mysql_error());
$number_of_rows = mysql_num_rows($result);
if ($number_of_rows >0)
{
echo ‘<strong>Updated Salvage Items :: </strong>’;
for ($y=1; $y<=($number_of_rows); $y++)
{
while ($newArray = mysql_fetch_array($result))
{
$id = $newArray[‘id’];
$name = $newArray[‘name’];
echo ‘<a href=”drops.php?id=’.$id.'”>’.$name.'</a> <strong>::</strong> ‘;
}
}
echo ‘<p>’;
}
echo ‘<hr align=”center” width=”50%”>’;
echo ‘</font></td>’;
echo ‘</tr>’;
echo ‘</table>’;
}
}
?>
Thanks for looking at it.