Jump to content


Photo

"expects parameter 1 to be resource"


  • Please log in to reply
7 replies to this topic

#1 wond3r

wond3r

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 March 2013 - 07:33 PM

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Muratcea_S_3014_hw5\index.php on line 101 Call Stack # Time Memory Function Location 1 0.0003 149672 {main}( ) ..\index.php:0 2 0.0031 157128 mysql_fetch_array ( ) ..\index.php:101

 

( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Muratcea_S_3014_hw5\index.php on line 149 Call Stack # Time Memory Function Location 1 0.0006 150632 {main}( ) ..\index.php:0 2 0.0048 158232 mysql_num_rows ( ) ..\index.php:149

Im not sure what to include here so I will show those specific areas...

 

<?php
		$con=0;
		while($row = mysql_fetch_array($movResults)){	
			if($con == 0) {
			echo "<div class=\"container\">
			<div class=\"row\">
			<div class=\"fourcol\">
				<div class=\"movImg\">
					<img src=\"images/".$row['products_thumb']."\" alt=\"".$row['products_name']."\">
			</div>
        	<div class=\"movTxt\">
            	<h3>".$row['products_name']."</h3>
            	<p>".$row['products_price']."</p>
								<a href=\"productdetail.php?id=".$row['products_id']."\">View Product.....</a>

        	</div>
        </div>";
		$con++;
			}else if($con == 1){
			echo "<div class=\"fourcol\">
				<div class=\"movImg\">
					<img src=\"images/".$row['products_thumb']."\" alt=\"".$row['products_name']."\">
			</div>
        	<div class=\"movTxt\">
            	<h3>".$row['products_name']."</h3>
            	<p>".$row['products_price']."</p>
								<a href=\"productdetail.php?id=".$row['products_id']."\">View Product.....</a>

        	</div>
        </div>";
		$con++;
			}else if($con == 2){
			echo"<div class=\"fourcol last\">	
			<div class=\"movImg\">
					<img src=\"images/".$row['products_thumb']."\" alt=\"".$row['products_name']."\">
			</div>
        	<div class=\"movTxt\">
            	<h3>".$row['products_name']."</h3>
            	<p>".$row['products_price']."</p>
								<a href=\"productdetail.php?id=".$row['products_id']."\">View Product.....</a>

        	</div>
        	</div>
			</div>
		</div>
		<div class=\"row\">";
		$con = 0;
			}
		}
		
		$numRows = mysql_num_rows($movResults);
		$div = $numRows%3; 
	
		if($div==1){
			echo"<div class=\"eightcol last\"></div></div></div>";
		}else if($div==2){
			echo"<div class=\"fourcol last\"></div></div></div>";
		}
	
		?>

 

 

I really dont understand whats happening. I'm new to this 



#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 10 March 2013 - 07:50 PM

mysql_error

 

try using it to see why your query failed


Edited by Barand, 10 March 2013 - 07:50 PM.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 wond3r

wond3r

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 March 2013 - 07:55 PM

mysql_error

 

try using it to see why your query failed

I was looking into that for the last 15 minutes and I cant figure out where to put(inside of the php code at the top, or in that php code I posted which is the error section) that or how to use it exactly.


Edited by wond3r, 10 March 2013 - 07:59 PM.


#4 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 10 March 2013 - 08:14 PM

the usual place is

 

$movResults = mysql_query($query) or die (mysql_error());


moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#5 wond3r

wond3r

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 March 2013 - 08:19 PM

the usual place is

 

$movResults = mysql_query($query) or die (mysql_error());

 

 

$movResults = mysql_query($allMov) or die (mysql_error());

 

 

 

No database selected


Edited by wond3r, 10 March 2013 - 08:21 PM.


#6 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 10 March 2013 - 08:22 PM

I don't know what your query is - you didn't post it. and I'm not clairvoyant

 

Substitute yours for $query. ::)


moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#7 wond3r

wond3r

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 March 2013 - 08:25 PM

this is my query at the top, sorry

 

<?php
	require_once("connect.php");
	
	if(isset($_GET['userSearch'])) {
		$srch=$_GET['userSearch'];
			$allMov = "SELECT * FROM tbl_products WHERE products_name LIKE '%".
			$srch."%' ORDER BY products_name";
		} else if (isset($_GET['nav'])) {
				$select=$_GET['nav'];
				$allMov = "SELECT * FROM tbl_products, tbl_cat, tbl_l_pc WHERE tbl_products.products_id =tbl_l_pc.products_id AND tbl_cat.cat_id=tbl_l_pc.cat_id AND tbl_cat.cat_name = '".$select."' ORDER BY tbl_products.products_name ASC";

		}
else{
		$allMov = "SELECT * FROM tbl_products ORDER BY products_name ASC";

	}	
	
$movResults = mysql_query($allMov) or die (mysql_error());



?>


#8 davidannis

davidannis

    Freak Dr.

  • Members
  • PipPipPip
  • 601 posts
  • LocationOkemos, MI USA

Posted 10 March 2013 - 09:06 PM

I'm guessing that you need to select a database or just failed to connect at all in connect.php.

 

Documentation can be found here: http://php.net/manua...l-select-db.php






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com