Jump to content

[SOLVED] Limiting output of database list with IF statement?


Anticrombie

Recommended Posts

Hey guys, I appreciate any help you can give. I'm new to php-MS SQL.

 

CURRENT STATUS: I have a page that pulls from a database and displays a full list. It is a database of movies, and the db holds info on the name, director, category, etc.

 

FINAL OUTPUT: I want the page to only display items that also have a particular category.

 

EXAMPLE: I want the user to be able to see only films in the 'animated' category.

 

Here is the current code to pull the info:

 

<?php
switch($view){
	case 'day':
		$date=strtotime($_GET['date']);
		$date_str="schedule_".strtolower(date("F_j_y_D",$date)).".php";
		include $date_str;
		break;

	case 'cat':
		if(connect()){
			global $conn;
			$exec=mssql_query($sql[$cat]['sql'],$conn);
			echo "<table border=0 cellpadding=0 cellspacing=0 class='movie_list'>";
			if(mssql_num_rows($exec)>0){
				echo "\n<tr>\n\t<td colspan='2' class='searchTitle'>";
				echo $sql[$cat]['display'];
				echo "\n\t</td>\n</tr>";
				while($result=mssql_fetch_array($exec)){
					echo "\n<tr>\n\t<td class='movieName'>\n\t\t";
					//echo "<a href=\"javascript:launchwin('schedule/details_film08.php?ID=".$result['FilmID']."', 'ch2', 'scrollbars=yes,width=500,height=525,left=45,top=25,screenX=45,screenY=25','mainwindow');\">".$result['Film_Title']."</a>";
					echo "<a href='schedule/details_film08.php?ID=".$result['FilmID']."&bw=575&bh=500' class='jcebox' style='text-decoration:none' title='".$result['Film_Title']."'>".$result['Film_Title']."</a>";
					echo "\n\t</td><td class='directorName'>";
					echo $result['Category'];
					echo "\n\t</td>";
					echo "\n</tr>";
				}
			}else{
				echo "<tr><td colspan>";
				echo "Your search returned no results.";
				echo "</td></tr>";
			}
			echo "\n</table>";
		}
}
?>





 

In the database, I have two options for category:

[CatNum] - which displays a category number

[Category] - which is the category name I want to display by. For instance, a category would be 'animated', and I want to show the list of only the animated movies.

 

Any help at all is appreciated (I really don't know what I'm doing :) )

Link to comment
Share on other sites

Got it...

 

I just added an IF wrapper in the middle of the function, instead of trying to limit the function before it runs. A bit neanderthal in that it probably runs clunky, but serves it's purpose.

 

I changed:

if(mssql_num_rows($exec)>0){
				echo "\n<tr>\n\t<td colspan='2' class='searchTitle'>";
				echo $sql[$cat]['display'];
				echo "\n\t</td>\n</tr>";
				while($result=mssql_fetch_array($exec)){
						echo "\n<tr>\n\t<td class='movieName'>\n\t\t";
						//echo "<a href=\"javascript:launchwin('schedule/details_film08.php?ID=".$result['FilmID']."', 'ch2', 'scrollbars=yes,width=500,height=525,left=45,top=25,screenX=45,screenY=25','mainwindow');\">".$result['Film_Title']."</a>";
						echo "<a href='schedule/details_film08.php?ID=".$result['FilmID']."&bw=575&bh=500' class='jcebox' style='text-decoration:none' title='".$result['Film_Title']."'>".$result['Film_Title']."</a>";
						echo "\n\t</td><td class='directorName'>";
						echo $result['FirstNm']." ".$result['LastNm'];
						echo "\n\t</td>";
						echo "\n</tr>";
				}

 

To

if(mssql_num_rows($exec)>0){
				echo "\n<tr>\n\t<td colspan='2' class='searchTitle'>";
				echo $sql[$cat]['display'];
				echo "\n\t</td>\n</tr>";
				while($result=mssql_fetch_array($exec)){
					if ($result['CatNum']=='1'){
						echo "\n<tr>\n\t<td class='movieName'>\n\t\t";
						//echo "<a href=\"javascript:launchwin('schedule/details_film08.php?ID=".$result['FilmID']."', 'ch2', 'scrollbars=yes,width=500,height=525,left=45,top=25,screenX=45,screenY=25','mainwindow');\">".$result['Film_Title']."</a>";
						echo "<a href='schedule/details_film08.php?ID=".$result['FilmID']."&bw=575&bh=500' class='jcebox' style='text-decoration:none' title='".$result['Film_Title']."'>".$result['Film_Title']."</a>";
						echo "\n\t</td><td class='directorName'>";
						echo $result['FirstNm']." ".$result['LastNm'];
						echo "\n\t</td>";
						echo "\n</tr>";
				}
				}

 

 

Basically wrapping the function in:

if ($result['CatNum']=='1'){ FUNCTION HERE }

 

Thanks again for everyone browsing my question, I know it's tough to figure out someone else's code sometimes.

 

 

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.