Page 1 of 1

Logic advice sought - trimming down the fat

Posted: Fri Aug 15, 2003 2:11 pm
by robster
Hi all,

I've got a dilema. I have two sections to my website (at least), but these two are so similar I can almost use the same code in both cases.

Here's what the two pages do:

Page 1
This page displays audio files, of which there are ONE per month.

Page 2
This page shows video files, of which there can be MANY per month.

On page 1, I wrote a cool lil script (for me being a newby) that checks through the database, and any time it finds an entry, it extracts the monthname from the table and displays it. Seeing as there is only ONE soundfile per month, this worked a treat.

Here is the code for Page 1 menu

Code: Select all

<!--soundfile MENU sidebar-->
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<?
	
	//get all the database info ordered by $dir and throw it thru da mix	
	$connection = mysql_connect($dbhost, $dbusername, $dbpassword);

  	$yeartravel   = $_GETї'yearly'];
  	$idtravel   = $_GETї'id'];	

	$boxtoptext  ='Choose year then month';
	include("box_top.php"); 
	
	
	$dir = "ASC";
	$content = mysql_db_query($dbname, "SELECT * FROM current_round ORDER BY id $dir");
	$Xcontent = mysql_fetch_array($content);



	//Show the date picker menu
	print "<a href="current_round_soundfile_archives.php?yearly=2003">2003 - </a>";
	print "<a href="current_round_soundfile_archives.php?yearly=2002">2002 - </a>";
	print "<a href="current_round_soundfile_archives.php?yearly=2001">2001 <br><br></a>";
	
	
	//show 12 months worth of $month

	$ShowMax = mysql_num_rows($content);




	for ($y=1; $y<=$ShowMax; $y++)
	{ 	
	$id = $Xcontentї"id"];
	$monthname = $Xcontentї"monthname"];
	$year = $Xcontentї"year"];
	
// if the year is the one chosen by the user, show the months in that year
	if ($year == $yeartravel)
	{
	print "<a href="current_round_soundfile_archives.php?id=$id&yearly=$year">$monthname</a><br>";
	
	}	
	$Xcontent = mysql_fetch_array($content);	
	}
	mysql_free_result($content);
	echo "<br>";	
	
   ?>
   </td>
   </tr>
   </table>
   <!--END soundfile MENU sidebar-->

OK, so now I get it working after a few bug fixes... VERY pleased with myself (remember, I'm a newby ;) ) and I move onto Page 2.

Remember Page 2 has MANY items per month, so when I try to apply the same code, I get many of the same month appearing. For example, if there are 5 items in January, I get 5 monthnames for January.

I know it's obvious now I've done it, but you know, I just can't think of how I can tell it to see that yes, we have at LEAST one entry in Jan, but only show jan once in the menu.

I'm not after actual code, I'm just after any ideas people might have on how to achieve this. I'd really appreciate anything people will throw at me. I'm so not a programmer, though I am enjoying this. This logic has gone beyond my (currently) feeble limits.

Thanks again, this forum is just fantastic. I can't wait till I'm good enough to start throwing suggestions back into the community and helping people myself.

:)

Rob

Posted: Fri Aug 15, 2003 3:06 pm
by McGruff
I didn't look at your code in detail but I think what you want is a way to output month outside of the loop which creates the list of items in that month.

Posted: Fri Aug 15, 2003 4:55 pm
by robster
Thanks for your suggestion.
I guess that could work... I'll have to think about it some more (your suggestion).

Basically I want it to come across a new month and say, ok, Jan is here, lets add jan to the menu.... then it would need to ignore the rest of the jans until it came to feb, then it would repeat... add feb to menu, ignore rest of febs, get to march... etc etc...

Any ideas on that or is that logic overly complicated?

Thanks again :)

Rob