Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Exclamation Warning: mysql_fetch_array() expects parameter 1 to be resource

    Please help?

    I have the same site in 2 places but it's not working properly in one, I get the error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\aandheurope.com\wwwroot\index.php on line 275

    Line 275:
    Code:
    while($row4 = mysql_fetch_array($result4))
    					{
    					echo '<a href="index.php?PageID=3&amp;CategoryID='.$CategoryID.'&amp;ProductID='.$row4['ProductID'].'"><img src="product-thumbs/'.$row4['PicturePath'].'" alt="'.$row4['$ProductName'].'" /><h4>'.$row4['ProductName'].'</h4></a>';	
    					}
    other relevant code
    Code:
    if($CategoryID >= 1){ 
    $tableName="ah_products";		 	
    	$limit = 10; 
    	$targetpage = "index.php";
    	$query = "SELECT COUNT(*) as num FROM $tableName WHERE CategoryID=$CategoryID";
    	$total_pages = mysql_fetch_array(mysql_query($query));
    	$total_pages = $total_pages['num'];
    
    	$stages = 3;
    	$page = mysql_escape_string($_REQUEST['pagec']);
    	if( isset($_REQUEST['pagec']) && ctype_digit($_REQUEST['pagec']) ) {
          $page = (int) $_GET['pagec'];
          $start = ($page - 1) * $limit;
    }else{
          $start = 0;   
    }
    
    
    
    
    $query4 = "SELECT * FROM ah_products INNER JOIN ah_productpics ON ah_products.ProductID=ah_productpics.ProductID WHERE CategoryID ='$CategoryID' LIMIT $start, $limit";
    	$result4 = mysql_query($query4);
    here are the sites:

    erroring site


    Working site

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jarv View Post
    Please help?

    I have the same site in 2 places but it's not working properly in one, I get the error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\aandheurope.com\wwwroot\index.php on line 275

    Line 275:
    Code:
    while($row4 = mysql_fetch_array($result4))
    					{
    					echo '<a href="index.php?PageID=3&amp;CategoryID='.$CategoryID.'&amp;ProductID='.$row4['ProductID'].'"><img src="product-thumbs/'.$row4['PicturePath'].'" alt="'.$row4['$ProductName'].'" /><h4>'.$row4['ProductName'].'</h4></a>';	
    					}
    other relevant code
    Code:
    if($CategoryID >= 1){ 
    $tableName="ah_products";		 	
    	$limit = 10; 
    	$targetpage = "index.php";
    	$query = "SELECT COUNT(*) as num FROM $tableName WHERE CategoryID=$CategoryID";
    	$total_pages = mysql_fetch_array(mysql_query($query));
    	$total_pages = $total_pages['num'];
    
    	$stages = 3;
    	$page = mysql_escape_string($_REQUEST['pagec']);
    	if( isset($_REQUEST['pagec']) && ctype_digit($_REQUEST['pagec']) ) {
          $page = (int) $_GET['pagec'];
          $start = ($page - 1) * $limit;
    }else{
          $start = 0;   
    }
    
    
    
    
    $query4 = "SELECT * FROM ah_products INNER JOIN ah_productpics ON ah_products.ProductID=ah_productpics.ProductID WHERE CategoryID ='$CategoryID' LIMIT $start, $limit";
    	$result4 = mysql_query($query4);
    here are the sites:

    erroring site


    Working site
    The problem is that your query has failed, so you're passing FALSE into mysql_fetch_array. You're not doing any error reporting on mysql_query, so we don't really know what's wrong - add an 'or die(mysql_error())' to mysql_query or an if condition.
    PHP Code:
    $result4 mysql_query($query4) or die(mysql_error());

    // OR
    $result4 mysql_query($query4);
    if(!
    $result){
        die(
    mysql_error());

    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You seem to have posted quite a few issues identical to this. The cause is always the same; you have not added appropriate error handling to your code to determine if your query is successful. This can be done with an or die() call or by using if statements to determine the results (since a failure is a boolean false).

  • #4
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    thanks, it said: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    I think my problem is in the following piece of code:
    Code:
    if($CategoryID >= 1){ 
    $tableName="ah_products";		 	
    	$limit = 10; 
    	$targetpage = "index.php";
    	$query = "SELECT COUNT(*) as num FROM $tableName WHERE CategoryID=$CategoryID";
    	$total_pages = mysql_fetch_array(mysql_query($query));
    	$total_pages = $total_pages['num'];
    
    	$stages = 3;
    	$page = mysql_escape_string($_REQUEST['pagec']);
    	if( isset($_REQUEST['pagec']) && ctype_digit($_REQUEST['pagec']) ) {
          $page = (int) $_GET['pagec'];
          $start = ($page - 1) * $limit;
    }else{
          $start = 0;   
    }

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    It could very well be. What's the parsed result of $query?

  • #6
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    the parsed result of $query?

    $query counts the number of pages for the pagination. the piece of code above comes from a separate page

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by jarv View Post
    the parsed result of $query?

    $query counts the number of pages for the pagination. the piece of code above comes from a separate page
    I know what the intention of it is. What's the parsed result of that string?

  • #8
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question

    how do I find out the parsed result of the string?

    Also, JQuery is not working this is an exact copy of the working site on the same server?!

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    jQuery is beyond the scope of this issue.
    To find the parsed results, you would use print $query;.

  • #10
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question

    that doesn't work?!

    Why doesn't this work an the same server?! hmm

  • #11
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jarv View Post
    that doesn't work?!

    Why doesn't this work an the same server?! hmm
    What do you mean it doesn't work? We're trying to find out what $query is before it goes into the mysql_query(). The error implies that it's empty, or at least, there's an empty string in it somewhere.
    Edit: I think it's actually $query4 we need to see
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #12
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    $query4 = SELECT * FROM ah_products INNER JOIN ah_productpics ON ah_products.ProductID=ah_productpics.ProductID WHERE CategoryID ='2' LIMIT ,

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by jarv View Post
    $query4 = SELECT * FROM ah_products INNER JOIN ah_productpics ON ah_products.ProductID=ah_productpics.ProductID WHERE CategoryID ='2' LIMIT ,
    Now run that query in your phpmyadmin and see what it says.

    Note that you have nothing after 'LIMIT' which could be a problem.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #14
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question

    yes, I got: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    but it works on my other site on the same server?!

    hmm

    so the problem lies here:


    Code:
    if($CategoryID >= 1){ 
    $tableName="ah_products";		 	
    	$limit = 10; 
    	$targetpage = "index.php";
    	$query = "SELECT COUNT(*) as num FROM $tableName WHERE CategoryID=$CategoryID";
    	
    	$total_pages = mysql_fetch_array(mysql_query($query));
    	$total_pages = $total_pages['num'];
    
    	$stages = 3;
    	$page = mysql_escape_string($_REQUEST['pagec']);
    	if( isset($_REQUEST['pagec']) && ctype_digit($_REQUEST['pagec']) ) {
          $page = (int) $_GET['pagec'];
          $start = ($page - 1) * $limit;
    }else{
          $start = 0;   
    }
    
    // Initial page num setup
    	if ($page == 0){$page = 1;}
    	$prev = $page - 1;	
    	$next = $page + 1;							
    	$lastpage = ceil($total_pages/$limit);		
    	$LastPagem1 = $lastpage - 1;
    $paginateproducts = '';
    	if($lastpage > 1)
    	{	
    	
    	$paginateproducts .= "<div id='paginate'>";
    		$paginateproducts .= "<div class='pagination'>";
    		// Previous
    		if ($page > 1){
    			$paginateproducts.= "<a href='$targetpage?pagec=$prev&pageu=1&CategoryID=$CategoryID' title='Previous Page'>&laquo; Previous</a>";
    		}else{
    			$paginateproducts.= "<span class='disabled' title='Previous page'>&laquo; Previous</span>";	}
    			
    
    		
    		// Pages	
    		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
    		{	
    			for ($counter = 1; $counter <= $lastpage; $counter++)
    			{
    				if ($counter == $page){
    					$paginateproducts.= "<a href='#' class='number current'>$counter</a>";
    				}else{
    					$paginateproducts.= "<a href='$targetpage?pagec=$counter&pageu=1&CategoryID=$CategoryID' class='number'>$counter</a>";}					
    			}
    		}
    		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
    		{
    			// Beginning only hide later pages
    			if($page < 1 + ($stages * 2))		
    			{
    				for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
    				{
    					if ($counter == $page){
    						$paginateproducts.= "<a href='#' class='number current'>$counter</a>";
    					}else{
    						$paginateproducts.= "<a href='$targetpage?pagec=$counter&pageu=1&CategoryID=$CategoryID' class='number'>$counter</a>";}					
    				}
    				$paginateproducts.= "...";
    				$paginateproducts.= "<a href='$targetpage?pagec=$LastPagem1&pageu=1&CategoryID=$CategoryID' class='number'>$LastPagem1</a>";
    				$paginateproducts.= "<a href='$targetpage?pagec=$lastpage&pageu=1&CategoryID=$CategoryID' class='number'>$lastpage</a>";		
    			}
    			// Middle hide some front and some back
    			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
    			{
    				$paginateproducts.= "<a href='$targetpage?pagec=1&pageu=1&CategoryID=$CategoryID' class='number'>1</a>";
    				$paginateproducts.= "<a href='$targetpage?pagec=2&pageu=1&CategoryID=$CategoryID' class='number'>2</a>";
    				$paginateproducts.= "...";
    				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
    				{
    					if ($counter == $page){
    						$paginateproducts.= "<span class='number current'>$counter</span>";
    					}else{
    						$paginateproducts.= "<a href='$targetpage?pagec=$counter&pageu=1&CategoryID=$CategoryID' class='number'>$counter</a>";}					
    				}
    				$paginateproducts.= "...";
    				$paginateproducts.= "<a href='$targetpage?pagec=$LastPagem1&pageu=1&CategoryID=$CategoryID' class='number'>$LastPagem1</a>";
    				$paginateproducts.= "<a href='$targetpage?pagec=$lastpage&pageu=1&CategoryID=$CategoryID' class='number'>$lastpage</a>";		
    			}
    			// End only hide early pages
    			else
    			{
    				$paginateproducts.= "<a href='$targetpage?pagec=1&pageu=1&CategoryID=$CategoryID' class='number'>1</a>";
    				$paginateproducts.= "<a href='$targetpage?pagec=2&pageu=1&CategoryID=$CategoryID' class='number'>2</a>";
    				$paginateproducts.= "...";
    				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
    				{
    					if ($counter == $page){
    						$paginateproducts.= "<a href='#' class='number current'>$counter</a>";
    					}else{
    						$paginateproducts.= "<a href='$targetpage?pagec=$counter&pageu=1&CategoryID=$CategoryID' class='number'>$counter</a>";}					
    				}
    			}
    		}
    					
    				// Next
    		if ($page < $counter - 1){ 
    			$paginateproducts.= "<a href='$targetpage?pagec=$next&pageu=1&CategoryID=$CategoryID' title='Next Page'>Next Page &raquo;</a>";
    		}else{
    			$paginateproducts.= "<span class='disabled' title='Next Page'>Next Page &raquo;</span>";
    			}
    			
    		$paginateproducts.= "</div>";
    		$paginateproducts.= "</div>";
    	}
    	}

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by jarv View Post
    but it works on my other site on the same server?!
    Doesn't mean a thing. Code that works fine on one website will work differently on another. Different things such as domains, file paths, database logins etc all come in to play.

    Have you even tried debugging this code line by line to see where its going wrong? - We keep telling you about this and you continue to ignore it and then post large chunks of code. Learn to debug Jarv, you'll be such a better programmer for it.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    jarv (01-25-2012)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •