simple question in PHP

Discussion in 'PHP' started by ludwig, Jul 27, 2006.

  1. #1
    Hi,

    I wonder if this line is correct. It seems not to work in my file

    
    if ( ($img_id <= $temp ) and ($temp < $img_id + 10)) {echo $temp;};
    
    Code (markup):
    I have 28 pictures to be shown, 10 per page, but only 2 pages show up

    thanks in advance
     
    ludwig, Jul 27, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try setting a new variable for $img_id+10 before you do the if statement.

    $img_id_max=$img_id+10;
    if ( ($img_id <= $temp ) and ($temp < $img_id_max)) {echo $temp;};
    PHP:
     
    mad4, Jul 27, 2006 IP
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    still not working, it shows like there are only 20, it shows 2 pages
     
    ludwig, Jul 27, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I assume img_id runs from 1 to 28? What is the temp variable?
     
    mad4, Jul 27, 2006 IP
  5. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #5
    
    function lesexamples ($sex)
    	{
    		if ($_GET[page_num] == "")
    			{$page_num = 1;} 
    			else {$page_num = $_GET[page_num];
    			};
    			
    		$k = mysql_query("SELECT * FROM lesexamples WHERE sex='{$sex}'");
    		$exemple_qty = mysql_num_rows($k);
    
    		$page_qty = ceil ($exemple_qty/10);
    		echo '<table width="100%" cellspacing="0" cellpadding="0" border="0">';
    		$img_id = ($page_id - 1)* 10 +1;
    		$img_id_max=$img_id+10;
    		while ($z = mysql_fetch_array($k)) {
    			$temp++;
    			if ( ($img_id <= $temp ) and ($temp < $img_id_max)) {echo $temp;};
    
    						
    			
    			};
    			
    	echo '<tr><td colspan="2" height="15"></td></tr>'; ?>
    		<tr><td colspan="2" height="15" align="center">
    		
    		<?
    		for ($i = 1; $i <= $page_qty; $i++)
    		{
    			if ($i == $page_num)
    				{ echo $page_num;} 
    				else { echo ' <a href="main.php?page_id=3&section_id='. $_GET[section_id] .'&page_num=' . $i . '">' . $i.'</a> '; };
    		}; ?>
    		
    	</td></tr>
    	<tr><td colspan="2" height="15" align="center">
    	
    	<?
    	if ($page_num != 1)							
    		{ 	$link_page_num = $page_num - 1;
    			echo '<a href="main.php?page_id=3&section_id='. $_GET[section_id] .'&page_num=' . $link_page_num . '">Previous</a>&nbsp;&nbsp;&nbsp;';}
    		else {echo 'Previous&nbsp;&nbsp;&nbsp;';}
    	if ($page_num != $page_qty)							
    		{ 	$link_page_num = $page_num + 1;
    			echo '&nbsp;&nbsp;&nbsp;<a href="main.php?page_id=3&section_id='. $_GET[section_id] .'&page_num=' . $link_page_num . '">Next </a>';}
    		else {echo '&nbsp;&nbsp;&nbsp;Next';}
    		
    	?>
    	</td></tr>
    	</table>
    	<?
    };
    
    Code (markup):
     
    ludwig, Jul 27, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I still can't see where the temp variable is being set?
     
    mad4, Jul 27, 2006 IP
    ludwig likes this.
  7. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #7
    it comes from the DB, We have fixed the problem now, but thank you for your help
     
    ludwig, Jul 27, 2006 IP