PDA

View Full Version : Displaying rows based on fields


Futility U
10-18-2006, 01:50 AM
I'm writing my own script to update a K-State fan site that I run. I'm a n00b at writing computer code. Arrays and such still are a little bit over my head. So I'm hoping somebody here will be able to tell me what I need to do just by looking at what I've got written so far.

Here is the page via browser that I'm working on (to give you a better idea of what I'm trying to do): http://www.wildcatvictory.com/daily_hotlinks/

My database is setup as follows:
table: daily_hotlinks
fields: link_name, url, source, category, date_week_day, date_month, date_day, date_year

And the code that I'm using:
<?
// Database connection info removed to protect from l33t h4ck3r5

$result = mysql_query("select * from daily_hotlinks ORDER BY id DESC"); // Select which table to pull information from

$find_id = mysql_query("select * from daily_hotlinks WHERE id "); // Select which table to pull information from

// Determine colors for alternating rows
$color1 = "#E2E2E2";
$color2 = "#FFFFFF";
$row_count = 0; // Set variable to zero to start first row at second color

// Output table data for Daily Hotlinks
echo "<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">";

// Pull the Daily Hotlinks information from the MySQL database
while($r=mysql_fetch_array($result))
{
// Put table field names into PHP variables
$link_name=$r["link_name"];
$url=$r["url"];
$source=$r["source"];
$category=$r["category"];
$date_day_week=$r["date_day_week"];
$date_month=$r["date_month"];
$date_day=$r["date_day"];
$date_year=$r["date_year"];

// Alternate the color of each row
$row_color = ($row_count % 2) ? $color1 : $color2;

// Echo your table row and table data that you want to be looped over and over here.
echo "<tr>";
echo "<td bgcolor=\"$row_color\" width=\"16\" /><img src=\"/images/icon/$category.gif\" /></td><td bgcolor=\"$row_color\" align=\"left\" valign=\"middle\" /><font id=\"daily_hotlinks\"><a href=\"$url\" target=\"_blank\" />$link_name</a></font> <font id=\"daily_hotlinks_source\">$source</font></td>";
echo "</tr>";

// Add 1 to the row count
$row_count++;

}

// End the table
echo "</table>";

?>

So, all this does is pull out ever single row in the daily_hotlinks table and display them individally.

What I want to be able to do is display the Hotlinks in this format:

Monday, 10/18/2006
Hotlink #1
Hotlink #2
Hotlink #3

Tuesday, 10/17/2006
Hotlink #1
Hotlink #2
Hotlink #3

Wedneday, 10/16/2006
Hotlink #1
Hotlink #2
Hotlink #3

.......

So, how do I take all of the rows and sort them by the date_week_day, date_month, date_day and date_year fields so I can display the current day followed by the previous 6 days of Hotlinks (I want to show 7 days of Hotlinks at a time, I'll setup an archive system later)?

And of course, Hotlink #1 for the most recent day will be the last row in the daily_hotlinks table, so the biggest id in the table.

Thanks in advance.

Futility U
10-18-2006, 03:37 AM
Nevermind... got it figured out.