Jump to content

Passing Parameters


Xtremer360

Recommended Posts

I have it setup to be passing the parameters of the id and the limit but it's not posting the right one. I hate trying to describe things.

 

http://kansasoutlawwrestling.com/v3/index.php

 

Should be self explainatory what's wrong here lol.

 

<div id="middle-bottom"> 
        <div id="bottom-right"> <img src="http://www.kansasoutlawwrestling.com/v3/images/columns.png" alt="" /> 
        	<?php
			news(3,10);
		?>
	</div>
        <!--End of bottom-right -->
        <div id="bottom-left"> <img src="http://www.kansasoutlawwrestling.com/v3/images/headlines.png" alt="" /> 
        	<?php
			news(2,10);
		?>
	</div>
        <!--End of bottom-left-->
        <div id="bottom-middle"> <img src="http://www.kansasoutlawwrestling.com/v3/images/rumors.png" alt="" /> 
        	<?php
			news(4,10);
		?>
	</div>
        <!--End of bottom-middle-->
      </div>
      <!--End of  middle-bottom-->

 

function news($type, $limit){
		$type = array(2, 3, 4);
		for($i = 0; $i < count($type); $i++){
			$olddate = '';
			print "<ul>";
			$selector = $type[$i];
			//query
			$query = "SELECT ecn.id AS id, ecn.title AS title, ecn.content AS content, ecn.postdate AS postdate FROM `efed_content_news` AS ecn WHERE ecn.public = '1' AND ecn.category_id = '$selector' ORDER BY ecn.postdate DESC, ecn.id DESC LIMIT $limit";
			$result = mysql_query ($query);
			while($row = mysql_fetch_assoc($result)){
				$fieldarray=array('id','content','title','postdate');
				foreach ($fieldarray as $fieldlabel){
					if (isset($row[$fieldlabel])){ 
						$$fieldlabel=$row[$fieldlabel];
						$$fieldlabel=cleanquerydata($$fieldlabel);
					}
				}
				$postdate = convertdate($postdate);
				if($postdate != $olddate){
					if($olddate == ''){
						print "<li><strong>".$postdate."</strong><ul>";
					}
					else{
						print "</ul></li><li class='date'><strong>".$postdate."</strong><ul>";
					}
				}
				print "<li><a href='backstage/content.php?p=news&id=".$id."'>".$title."</a></li>";
				$olddate = $postdate;
			}
			print "</ul></li></ul>";
		}
		}

Link to comment
https://forums.phpfreaks.com/topic/193844-passing-parameters/
Share on other sites

No idea but obviously what should be happening is headlines should only be listing the stories that has a category_id of 2, rumors should only be listing the stories that has a category_id of 3, and columns should only be listing the stories that has a category_id of 4.

Link to comment
https://forums.phpfreaks.com/topic/193844-passing-parameters/#findComment-1020190
Share on other sites

the news script is doing this:

setting $type to an array with 3 values: 2, 3, 4

looping through the $type array

  setting $selector to $type[$i] (which is the current value from $type on this loop) so on the first loop, it is 2, the second loop is 3 and the third loop is 4. Therefore, $selector is equalling: 2, 3 or 4 depending on the loop number.

  $query is using $selector in it each time you loop, hence, you get one article of each type from the database. not 3 of the same.

 

what does $limit represent? The max number of articles to display per category? If so, this value should be used to limit the number of times the for () loops, OR you should just use $limit to SELECT no more than that many articles form the database, THEN loop on the results and output them (this is a better way IMO as it remove the need for the outer for loop all together)

 

I would do something like:

function news($type, $limit)
{
   // validate parameter data first
   $query = "SELECT * FROM dataTable WHERE type=$type LIMIT $limit";
   // send query, verify we get results
   while ($result = mysql_fetch_assoc($queryResults))
   {
      // output article data where/how desired
   }
}

 

The while($result ...) loop will only loop $limit number of time at the most (possibly less depending on how much data is in the table) and you will only get data where type = $type.

Link to comment
https://forums.phpfreaks.com/topic/193844-passing-parameters/#findComment-1020204
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.