Jump to content

expects parameter 1 to be resource error


pavankat

Recommended Posts

I keep getting this error when I run the following code: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\vitamin-k-tracker\my-meal-planner.php on line 29

 

<?php include 'top.php'; ?>
<?php

if (!loggedin())
{//1 if start
header('Location: need-to-log-in-mmp.php');
}//1 if end
?>
    <title>My Meal Planner - Vitamin K Tracker</title>
</head>

<div id="container">

<?php include 'header.php'; ?>

<?php include 'nav.php'; ?>
<?php
//do sql query to return the foods and nutrients that a person added to their que
//
// we're doing a left join between the foods and user foods table connected by the id


$queryc = "SELECT
`foods.id`, `foods.name`, `foods.source`, `users_foods.food_id`
FROM `foods`
LEFT JOIN users_foods
ON foods.id=users_foods.food_id";
$query_runc = mysql_query($queryc);

//error on the line below:
while ($rowc = mysql_fetch_array($query_runc)){

	echo 'ok';
}
     

?>




<div id="content-container">

<div id="content_for_site">
	<h2>My Meal Planner</h2>	<br />	
                      
	     


	      
	        	
                        My Meal Que:
		<br />
		<ul>
			<form>
			<li><input type="checkbox" name="meal_one" value="meal_one" /> Meal One</li>
			How many servings will you have? <input type="text" name="meal_one_servings"><br /><br />
			 <li><input type="checkbox" name="food_one" value="food_one" /> Food One</li>
			How many servings will you have? <input type="text" name="meal_one_servings">
			</form>

		</ul>
		<input type="submit" value="delete" name="delete"><br />
		<input type="submit" value="add to calendar" name="add_to_calendar">

		<br /><br />
		<a href="create-a-meal.php">Create A Meal & add to your Meal Que</a><br />
		<a href="find-a-meal.php">Find a Meal or Food to Add to your Meal Que</a>

	</div>




<div id="clear"></div>
<?php include 'footer.php'; ?>


</div>
</div>

Thanks dude. Apparently it said that foods.id didn't exist - but it did.

 

So I re wrote the query like this:

$queryc = "SELECT

`name`, `source`, `food_id`

FROM `foods`

LEFT JOIN users_foods

ON foods.id=users_foods.food_id";

 

and it worked. But I used foods.id at the bottom.

 

Not sure why that happened.

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.