Jump to content

[SOLVED] Problem with Yearly Increment and Corresponding #of entries.


pets2soul

Recommended Posts

Wazzzup people,

 

I'm trying to make a index sort of page, which will categorize the database entries into years,

from 2006 to date("y")-1. Also I want to show the number of entries in each year.

 

This is probably simple, but I'm jammed some where...below is my code, please kindly let me

know how should I correct and improve it. Thank you belly machi!

 

<?php
echo "<table width='300' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td colspan='3' height='38' align='left' valign='top'>
<a href='dataentry.php'>Add</a>
<a href='datalist.php'>List</a>
<a href='annuallist.php'>Annual</a></td>
    </tr>";

$con=mysql_connect("servername","username","password") or
die('Could not connect: '.mysql_error());

mysql_select_db("dbname",$con);

$start_y='2006';
$end_y=date("y")-1;

for($i=$start_y; $i<$end_y; i++){

  $year="'$i-01-01' AND '$i-12-31'";

  $q = "select count(*) as num_ent1 from table WHERE date BETWEEN $year";
  $res = mysql_query($q) or die('Problem with query: ' . $q . '<br>' . mysql_error());
  $rw = mysql_fetch_assoc($res);

  echo "<tr>
  <td width='100' height='28'>Year</td>
  <td width='100'># of Entries</td>
  <td width='100'>Enter</td>
  </tr>";

    echo "<tr>";
    echo "<td height='28'>".$i."</td>";
    echo "<td>".$rw['num_ent1']."</td>";
    echo "<td><a href=dataedit.php?".$i.">Go</a></td>";
    echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.