Jump to content

[SOLVED] Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean giv


sashi34u

Recommended Posts

I have been trying to use the mysqli_fetch_row ($result) command unsuccessfully. I want to retrieve the information row by row and display it on the browser. Can any one please point out the error I have made. I am pasting the code below

 

Thanks,

Sashi

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<!-- #BeginTemplate "master.dwt" -->

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- #BeginEditable "doctitle" -->
<title>Home</title>
<!-- #EndEditable -->
<link href="styles/style2.css" media="screen" rel="stylesheet" title="CSS" type="text/css" />
<style type="text/css">
.style1 {
text-align: right;
}
</style>
</head>

<body>

<!-- Begin Container -->
<div id="container">
<!-- Begin Masthead -->
<div id="masthead">
	<img alt="" height="118" src="images/parking_lot_1.jpg" width="391" /><h1 class="style1">
	 </h1>
	<h1 class="style1">Parking 
	Lot Information</h1>
</div>
<!-- End Masthead -->
<!-- Begin Navigation -->
<div id="navigation">
	<ul>
		<li><a href="default.html">Home</a></li>
		<li><a href="about/about.htm">Background</a></li>
		<li><a href="news/news.htm">About</a></li>
		<li><a href="products/products.htm">Visitor Information</a></li>
		<li><a href="services/services.htm">Links</a></li>
		<li><a href="contact/contact.htm">Contact</a></li>
	</ul>
</div>
<!-- End Navigation -->
<!-- Begin Page Content -->
<div id="page_content">
<form name= "Criteria_select" action="default.php" method="post">	
<br>
<div align="center">
<select name="criteria">
<option value=""> Select the Criteria</option>
<option value="Distance">Distance</option>
<option value="Empty spaces">Empty spaces</option>	
</form>
<form name= "Records" action="default.php" method="post">	
<br>
<div align="center">
<select name="records">
<option value=""> Select the Number of records you want to fetch</option>
<option value="1">1</option>
<option value="2">2</option>	
<option value="3">3</option>	
<option value="4">4</option>	
<option value="5">5</option>	
</form>
<br/>
<form name= "building_select" action="default.php" method="post">
<br>
<div align="center">
<select name="name">
<option value=""> Select a Building</option>
<option value="Agnew Hall">Agnew Hall</option>
      <option value="Air Conditioning Facility">Air Conditioning Facility</option>
      <option value="Ambler Johnston Hall">Ambler Johnston Hall</option>
      <option value="Architecture Annex">Architecture Annex</option>
      <option value="Armory">Armory</option>
      <option value="Art and Design Learning Center">Art and Design Learning Center</option>
      <option value="Barringer Hall">Barringer Hall</option>
      <option value="Bio informatics phase I">Bio informatics phase I</option>
      <option value="Bio informatics phase II">Bio informatics phase II</option>
      <option value="Bishop-Favrao Hall">Bishop-Favrao Hall</option>
      <option value="Brodie Hall">Brodie Hall</option>
      <option value="Building 270F">Building 270F</option>
      <option value="Burchard Hall">Burchard Hall</option>
      <option value="Burke Johnston Student Center">Burke Johnston Student Center</option>
      <option value="Burrows/Burleson Tennis Center">Burrows/Burleson Tennis Center</option>
      <option value="Burruss Hall">Burruss Hall</option>
      <option value="Campbell Hall">Campbell Hall</option>
      <option value="Cassell Coliseum">Cassell Coliseum</option>
      <option value="Central Stores">Central Stores</option>
      <option value="Cheatham Hall">Cheatham Hall</option>
      <option value="Chemistry/Physics Building">Chemistry/Physics Building</option>
      <option value="Cochrane Hall">Cochrane Hall</option>
      <option value="College of Science Admin. Bldg.">College of Science Admin. Bldg.</option>
      <option value="Cowgill Hall">Cowgill Hall</option>
      <option value="Cranwell International Center">Cranwell International Center</option>
      <option value="Dairy Science Complex">Dairy Science Complex</option>
      <option value="Davidson Hall">Davidson Hall</option>
      <option value="Derring Hall">Derring Hall</option>
      <option value="Dietrick Hall">Dietrick Hall</option>
      <option value="Durham Hall">Durham Hall</option>
      <option value="Eggleston Hall">Eggleston Hall</option>
      <option value="Engel Hall">Engel Hall</option>
      <option value="English Field">English Field</option>
      <option value="Femoyer Hall">Femoyer Hall</option>
      <option value="Fleet Services">Fleet Services</option>
      <option value="Food Science and Technology">Food Science and Technology</option>
      <option value="Fralin Biotechnology Center">Fralin Biotechnology Center</option>
      <option value="Golf Course Clubhouse">Golf Course Clubhouse</option>
      <option value="Graduate Life Center at Donaldson Brown">Graduate Life Center at Donaldson Brown</option>
      <option value="Greenhouses">Greenhouses</option>
      <option value="Hahn Hall">Hahn Hall</option>
      <option value="Hahn Horticulture Gardens">Hahn Horticulture Gardens</option>
      <option value="Hancock Hall">Hancock Hall</option>
      <option value="Harper Hall">Harper Hall</option>
      <option value="Harry T.Peters Large Animal Hospital">Harry T.Peters Large Animal Hospital</option>
      <option value="Health and Safety Building">Health and Safety Building</option>
      <option value="Henderson Hall">Henderson Hall</option>
      <option value="Hillcrest Hall">Hillcrest Hall</option>
      <option value="Holden Hall">Holden Hall</option>
      <option value="Holtzman Alumni Center">Holtzman Alumni Center</option>
      <option value="Hutcheson Hall">Hutcheson Hall</option>
      <option value="Institute of Critical Technology and Applied Science">Institute of Critical Technology and Applied Science</option>
      <option value="Jamerson Athletic Center">Jamerson Athletic Center</option>
      <option value="Johnson Hall">Johnson Hall</option>
      <option value="Lane Hall">Lane Hall</option>
      <option value="Lane Stadium/Worsham Field">Lane Stadium/Worsham Field</option>
      <option value="Latham Hall">Latham Hall</option>
      <option value="Lee Hall">Lee Hall</option>
      <option value="Life Sciences I">Life Sciences I</option>
      <option value="Litton-Reaves Hall">Litton-Reaves Hall</option>
      <option value="Major Williams Hall">Major Williams Hall</option>
      <option value="McBryde Hall">McBryde Hall</option>
      <option value="McComas Hall">McComas Hall</option>
      <option value="Media Annex">Media Annex</option>
      <option value="Media Building">Media Building</option>
      <option value="Merryman Athletic Center">Merryman Athletic Center</option>
      <option value="Miles Hall">Miles Hall</option>
      <option value="Military Building">Military Building</option>
      <option value="Monteith Hall">Monteith Hall</option>
      <option value="New Residence Hall-Career Services Site">New Residence Hall-Career Services Site</option>
      <option value="New Residence Hall-East">New Residence Hall-East</option>
      <option value="Newman Hall">Newman Hall</option>
      <option value="Newman Library">Newman Library</option>
      <option value="Norris Hall">Norris Hall</option>
      <option value="O’Shaughnessy Hall">O’Shaughnessy Hall</option>
      <option value="Old Security Building">Old Security Building</option>
      <option value="Owens Hall">Owens Hall</option>
      <option value="Pamplin Hall">Pamplin Hall</option>
      <option value="Parking Services">Parking Services</option>
      <option value="Patton Hall">Patton Hall</option>
      <option value="Payne Hall">Payne Hall</option>
      <option value="Peddrew-Yates Residence Hall">Peddrew-Yates Residence Hall</option>
      <option value="Performing Arts Building">Performing Arts Building</option>
      <option value="Power Plant">Power Plant</option>
      <option value="Price Hall">Price Hall</option>
      <option value="Pritchard Hall">Pritchard Hall</option>
      <option value="Randolph Hall">Randolph Hall</option>
      <option value="Rasche Hall">Rasche Hall</option>
      <option value="Rector Field House">Rector Field House</option>
      <option value="Richard B. Talbot Educational Resources Center">Richard B. Talbot Educational Resources Center</option>
      <option value="Robeson Hall">Robeson Hall</option>
      <option value="Sandy Hall">Sandy Hall</option>
      <option value="Saunders hall">Saunders hall</option>
      <option value="Seitz Hall">Seitz Hall</option>
      <option value="Shanks Hall">Shanks Hall</option>
      <option value="Shultz Hall">Shultz Hall</option>
      <option value="Skelton Conference Center">Skelton Conference Center</option>
      <option value="Slusher Hall">Slusher Hall</option>
      <option value="Smith Career Center">Smith Career Center</option>
      <option value="Smyth Hall">Smyth Hall</option>
      <option value="Solitude">Solitude</option>
      <option value="Southgate Center">Southgate Center</option>
      <option value="Squires Student Center">Squires Student Center</option>
      <option value="Sterrett Facilities Complex">Sterrett Facilities Complex</option>
      <option value="Student Services Building">Student Services Building</option>
      <option value="Surge Space Building">Surge Space Building</option>
      <option value="The Grove">The Grove</option>
      <option value="The Inn at Virginia Tech">The Inn at Virginia Tech</option>
      <option value="Thomas Hall">Thomas Hall</option>
      <option value="Torgersen Hall">Torgersen Hall</option>
      <option value="University Bookstore">University Bookstore</option>
      <option value="University Club">University Club</option>
      <option value="Vawter Hall">Vawter Hall</option>
      <option value="Virginia-Maryland Regional College of Veterinary Medicine">Virginia-Maryland Regional College of Veterinary Medicine</option>
      <option value="Visitor Information Center">Visitor Information Center</option>
      <option value="Wallace Annex">Wallace Annex</option>
      <option value="Wallace Hall">Wallace Hall</option>
      <option value="War Memorial Chapel">War Memorial Chapel</option>
      <option value="War Memorial Hall">War Memorial Hall</option>
      <option value="Whittemore Hall">Whittemore Hall</option>
      <option value="William E. Lavery Health Research Center">William E. Lavery Health Research Center</option>
      <option value="Williams Hall">Williams Hall</option>
      <option value="Women's Softball Field">Women's Softball Field</option>
      <option value="Wright House">Wright House</option>
</select>

</form>
<input type="submit" value="Submit" />
<br>
<?php 
// Connects to your Database
$host="*****";
$user="*****";
$password="*****";
$dbname="*****";
$cxn=mysqli_connect($host, $user, $password, $dbname) ;
if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
{
	$error=mysqli_error($cxn);
	echo "$error";
	die();
}
//Define the variables for Day and Month
$criteria=$_POST["criteria"];
$build=$_POST["name"];
$records=$_POST["records"];
$i=0;
$Today=date("l");
$Month=date("F");
$low_speed=2.5;
$high_speed=4;
$hour=date("G");
$minute=date("i");
if ($minute>=00 && $minute<=14)
{
	$minute=00;
}
elseif ($minute>=15 && $minute<=29)
{
	$minute=15;
}
elseif ($minute>=30 && $minute<=44)
{
	$minute=30;
}
else
{
	$minute=45;
}
$times="$hour:$minute";
echo $criteria;
if ($criteria=="Distance")
{
$sql="SELECT buildingname, parking_lot_name, (FS+COM+RES+FS_COM+VISITOR+GEN) AS total_spaces, (TIMED+METER) AS Metered, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy, Image where (buildings.buildingcode=occupancy.building AND  buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times' ORDER BY DESC Distance";
$data = mysqli_query($cxn,$sql);
if (!$data==mysqli_query($cxn,$sql))
{
	$error=mysqli_error($cxn);
	echo "$error";
	die();
}
echo "<br>";
echo "<table border='1' cellspacing='5' cellpadding='2'>";
echo "<tr>\n
	<th>Building</th>\n
	<th>Parking Lot</th>\n
	<th>Total Spaces</th>\n
	<th>Metered Spaces</th>\n
	<th>Estimated Number of Empty Spaces</th>\n
	<th>Distance (Feet)</th>\n
	<th>Estimated walking time to the building</th>\n
</tr>\n";

While ($i<$records)
{
$row=mysqli_fetch_row($data);
$building = $row[0];
$parking_lot = $row[1];
$total_spaces = $row[2];
$Metered = $row[3];
$Number_of_Empty_Spaces = $row[4];
$Distance = $row[5];
$time_l = $row[6];
$time_h=$row[7];
$location=$row[8];
echo "<tr>\n
	      <td>$building</td>\n
	      <td>$parking_lot</td>\n   
	      <td>$total_spaces</td>\n
	      <td>$Metered</td>\n
	      <td>$Number_of_Empty_Spaces</td>\n
	      <td>$Distance</td>\n
	      <td>$time_h - $time_l mins</td>\n      
</tr>\n";
$i++;
}
/*	
while ($row=mysqli_fetch_array($data))
{
	extract($row);
$building = $row[0];
$parking_lot = $row[1];
$total_spaces = $row[2];
$Metered = $row[3];
$Number_of_Empty_Spaces = $row[4];
$Distance = $row[5];
$time_l = $row[6];
$time_h=$row[7];
$location=$row[8];	
echo "<tr>\n
	      <td>$building</td>\n
	      <td>$parking_lot</td>\n   
	      <td>$total_spaces</td>\n
	      <td>$Metered</td>\n
	      <td>$Number_of_Empty_Spaces</td>\n
	      <td>$Distance</td>\n
	      <td>$time_h - $time_l mins</td>\n      
</tr>\n";
}
*/
echo "</table>\n";
echo "</p>\n";
echo '<img src="imgtest.php?id=' . $building . '" border="5" alt="' . $build . '">';

}

elseif ($criteria=="Empty spaces")
{
$sql="SELECT buildingname, parking_lot_name, (FS+COM+RES+FS_COM+VISITOR+GEN) AS total_spaces, (TIMED+METER) AS Metered, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy, Image where (buildings.buildingcode=occupancy.building AND  buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times' ORDER BY DESC empty_spaces";
$data = mysqli_query($cxn,$sql);
if (!$data=mysqli_query($cxn,$sql))
{
	$error=mysqli_error($cxn);
	echo "$error";
	die();
}
echo "<br>";
echo "<table border='1' cellspacing='5' cellpadding='2'>";
echo "<tr>\n
	<th>Building</th>\n
	<th>Parking Lot</th>\n
	<th>Total Spaces</th>\n
	<th>Metered Spaces</th>\n
	<th>Estimated Number of Empty Spaces</th>\n
	<th>Distance (Feet)</th>\n
	<th>Estimated walking time to the building</th>\n
</tr>\n";

While ($i<$records)
{
$row=mysqli_fetch_row($data);
$building = $row[0];
$parking_lot = $row[1];
$total_spaces = $row[2];
$Metered = $row[3];
$Number_of_Empty_Spaces = $row[4];
$Distance = $row[5];
$time_l = $row[6];
$time_h=$row[7];
$location=$row[8];
echo "<tr>\n
	      <td>$building</td>\n
	      <td>$parking_lot</td>\n   
	      <td>$total_spaces</td>\n
	      <td>$Metered</td>\n
	      <td>$Number_of_Empty_Spaces</td>\n
	      <td>$Distance</td>\n
	      <td>$time_h - $time_l mins</td>\n      
</tr>\n";
$i++;
}
/*	
while ($row=mysqli_fetch_array($data))
{
	extract($row);
$building = $row[0];
$parking_lot = $row[1];
$total_spaces = $row[2];
$Metered = $row[3];
$Number_of_Empty_Spaces = $row[4];
$Distance = $row[5];
$time_l = $row[6];
$time_h=$row[7];
$location=$row[8];	
echo "<tr>\n
	      <td>$building</td>\n
	      <td>$parking_lot</td>\n   
	      <td>$total_spaces</td>\n
	      <td>$Metered</td>\n
	      <td>$Number_of_Empty_Spaces</td>\n
	      <td>$Distance</td>\n
	      <td>$time_h - $time_l mins</td>\n      
</tr>\n";
}
*/
echo "</table>\n";
echo "</p>\n";
echo '<img src="imgtest.php?id=' . $building . '" border="5" alt="' . $build . '">';


}

else
{
$sql="SELECT buildingname, parking_lot_name, (FS+COM+RES+FS_COM+VISITOR+GEN) AS total_spaces, (TIMED+METER) AS Metered, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy, Image where (buildings.buildingcode=occupancy.building AND  buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times'";
$data = mysqli_query($cxn,$sql);
if (!$data=mysqli_query($cxn,$sql))
{
	$error=mysqli_error($cxn);
	echo "$error";
	die();
}
echo "<br>";
echo "<table border='1' cellspacing='5' cellpadding='2'>";
echo "<tr>\n
	<th>Building</th>\n
	<th>Parking Lot</th>\n
	<th>Total Spaces</th>\n
	<th>Metered Spaces</th>\n
	<th>Estimated Number of Empty Spaces</th>\n
	<th>Distance (Feet)</th>\n
	<th>Estimated walking time to the building</th>\n
</tr>\n";

While ($i<$records)
{
$row=mysqli_fetch_row($data);
$building = $row[0];
$parking_lot = $row[1];
$total_spaces = $row[2];
$Metered = $row[3];
$Number_of_Empty_Spaces = $row[4];
$Distance = $row[5];
$time_l = $row[6];
$time_h=$row[7];
$location=$row[8];
echo "<tr>\n
	      <td>$building</td>\n
	      <td>$parking_lot</td>\n   
	      <td>$total_spaces</td>\n
	      <td>$Metered</td>\n
	      <td>$Number_of_Empty_Spaces</td>\n
	      <td>$Distance</td>\n
	      <td>$time_h - $time_l mins</td>\n      
</tr>\n";
$i++;
}
/*	
while ($row=mysqli_fetch_array($data))
{
	extract($row);
$building = $row[0];
$parking_lot = $row[1];
$total_spaces = $row[2];
$Metered = $row[3];
$Number_of_Empty_Spaces = $row[4];
$Distance = $row[5];
$time_l = $row[6];
$time_h=$row[7];
$location=$row[8];	
echo "<tr>\n
	      <td>$building</td>\n
	      <td>$parking_lot</td>\n   
	      <td>$total_spaces</td>\n
	      <td>$Metered</td>\n
	      <td>$Number_of_Empty_Spaces</td>\n
	      <td>$Distance</td>\n
	      <td>$time_h - $time_l mins</td>\n      
</tr>\n";
}
*/
echo "</table>\n";
echo "</p>\n";
echo '<img src="imgtest.php?id=' . $building . '" border="5" alt="' . $build . '">';

}
?>
</div>
	</div>
<!-- End Page Content -->
<!-- Begin Footer -->
<div id="footer">
	<p><a href="default.html">Home</a> | <a href="about/about.htm">Background</a> |
	<a href="calendar/calendar.htm">About</a> |
	<a href="contact/contact.htm">Visitor Information</a> |
	<a href="employees/employees.htm">Links</a> |
	<a href="employment/employment.htm">Contact</a> 
	</p>

</div>
<!-- End Footer --></div>
<!-- End Container -->

</body>

<!-- #EndTemplate -->

</html>

 

 

 

Link to comment
Share on other sites

In the following, there should only be one = sign -

 

if (!$data==mysqli_query($cxn,$sql))

 

Two == signs are a comparison operator (you are comparing $data with the result of the mysqli_query(). One = sign is an assignment operator (you want to assign the result of the mysqli_query() to $data and then test if that is true/false.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.