如何清除以前查询的查询结果?

时间:2015-07-02 12:51:18

标签: mysqli overlap

所以我有这些查询,并且在上一次查询中,我试图获得的结果一直被以前成功查询的结果所取代,我真的不知道该怎么做。我已经尝试过不同的方法来调用查询等等但它不断给我带来前一个的答案。它们全部位于不同的页面上,由include_once调用。

这是我试图获得结果的查询:



$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT nombre, apellido  FROM socios WHERE nombreClub = ' " . $_SESSION["clubDetail"] . " ' ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
		$nombreSocio = $row["nombre"];
		$apellidoSocio = $row["apellido"];
    }
} else {
    echo "0 results";
}

$conn->close();




这是我实际得到的结果:



try {
	
    $conn = new PDO('mysql:host=localhost;dbname=4h', $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	
			$sql = "SELECT COUNT(*) FROM club4h";
			if ($res = $conn->query($sql)) {

				/* Check the number of rows that match the SELECT statement */
			  if ($res->fetchColumn() > 0) {

					/* Issue the real SELECT statement and work with the results */
					 $sql = "SELECT id, nombreClub, liderVoluntario FROM club4h";
				   foreach ($conn->query($sql) as $row) {
						$nombreClub[] = $row["nombreClub"];
						$liderVoluntario[] = $row["liderVoluntario"];
						$id[] = $row["id"];
					 }
				}
				/* No rows matched -- do something else */
			  else {
				  print "No rows matched the query.";
				}
			}
			
	$res = null;
	$conn = null;
	$sql = null;
	
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}






array (size=8)
  'nombre' => string 'jose' (length=4)
  0 => string 'jose' (length=4)
  'apellido' => string 'christian' (length=9)
  1 => string 'christian' (length=9)
  'titulo' => string 'lider voluntario' (length=16)
  2 => string 'lider voluntario' (length=16)
  'unidadProg' => string '362 - sabana grande' (length=19)
  3 => string '362 - sabana grande' (length=19)




如果您需要更多代码或更多信息,请向我询问。也许这很容易,但我只是没有看到它。感谢。

1 个答案:

答案 0 :(得分:0)

请在开始新查询之前尝试将$ result设置为NULL,如下所示

$result =NULL;
$result = $conn->query($sql);
相关问题