Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in


cerberus478

Recommended Posts

Hi

 

I know this is probably a stupid question but I have this error

 

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /var/www/vhosts/server.com/httpdocs/cms/classes/Page.php on line 2785 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/server.com/httpdocs/cms/classes/Page.php on line 2787 

 

On line 2785 is

$combineArr = mysql_num_rows($query);

On line 2787

while( $result1 = mysql_fetch_object($query) ){

This is the entire code

function putGrid($pageid){
		global $_GRID_FRAMES_TABLE, $_GRID_TABLE, $_GRID_CROSS_GRID_FRAMES_TABLE, $_GRID_CROSS_PAGES_TABLE, $_HTTP_ADDRESS;
        $i=0;
        $cpt = 1;
        $str = '';
        $whichCount = 1;
        $query = mysql_query("SELECT * FROM $_GRID_TABLE WHERE id_page='$pageid'");
        //return mysql_num_rows($query) or mysql_error();
        //return $query;
        $combineArr = mysql_num_rows($query);

        while( $result1 = mysql_fetch_object($query) ){

        	if($whichCount == 1){
				$gridClass="grid-active";
				$style = "position: absolute; left:0%; top:0; width:100%;";	
			}else{
				$gridClass="grid-inactive";	
				$style = "position: absolute; left:-100%; top:0; width:100%;";	
			}

        	if($whichCount == 1){
				$str.='<div id="grid-slide'.$i.'" class="grid-slide '.$gridClass.'" style="'.$style.'">';
	            $str.=		'<div class="grid-slide-inner">';
	            $str.=			'<div class="grid-banner-content grid-banner-left">';
	            $str.=				'<div class="grid-banner-header">';
	            $str.=				'</div>';
	            $str.=				'<div class="grid-banner-copy">';
	            $str.=					'<ul id="gallery">';	
			}

			$str.=						'<li>';
            $str.=							'<img src="'.$_HTTP_ADDRESS.'products_images/'.$result->image.'">';
            $str.=							'<span>';
            $str.=								'<h3>'.$result->name.'</h3>';
            $str.=								$result->description;
            $str.=							'</span>';	
            $str.=						'</li>';

			if($whichCount % 9 == 0 && $whichCount < $combineArr){

				$i++;

				$str.=					'</ul>';
	            $str.=				'</div>';
	            $str.=			'</div>';
	            $str.=		'</div>';
	            $str.='</div>';		

	            $str.='<div id="grid-slide'.$i.'" class="grid-slide '.$gridClass.'" style="'.$style.'">';
	            $str.=		'<div class="grid-slide-inner">';
	            $str.=			'<div class="grid-banner-content grid-banner-left">';
	            $str.=				'<div class="grid-banner-header">';
	            $str.=				'</div>';
	            $str.=				'<div class="grid-banner-copy">';
	            $str.=					'<ul id="gallery">';					
			}
			
			if($whichCount == $combineArr){
				
				$str.=					'</ul>';
	            $str.=				'</div>';
	            $str.=			'</div>';
	            $str.=		'</div>';
	            $str.='</div>';				
	        }
			$whichCount++;
            $cpt++;
        }
        return $str;
    }

The best place to start is with the query.

 

Change

 $query = mysql_query("SELECT * FROM $_GRID_TABLE WHERE id_page='$pageid'");

To

$query = mysql_query("SELECT * FROM $_GRID_TABLE WHERE id_page='$pageid'")or die('Error:' . mysql_error() . "SELECT * FROM $_GRID_TABLE WHERE id_page='$pageid'");

That should show any errors & show you the exact query that's being run. I'd suggest removing the crappy error code and replacing it with something a bit nicer once the error is sorted.

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.