我試圖從數據庫中獲取信息,但查詢只運行第一行! 我已經嘗試了很多東西,但沒有奏效;我不知道爲什麼。 get方法是由數據庫表中填寫PDO查詢只運行第一次
的問題是,在第一個查詢'SELECT CouID FROM CoursesC WHERE StuID = :ID '
如果我更改查詢到'SELECT CouID FROM CoursesC'
它工作正常!
我呈現的數據爲<select>
一個模式
表單代碼
<form action="<?php $_SERVER['PHP_SELF']?>" method="GET" id="contact">
<table id="studenttable">
<tr>
<th></th>
<th>Student ID</th>
<th>Student Name</th>
<th>Student Passed Credits</th>
<th>Action</th>
</tr>
<?php
require('check.php');
$query = $conn->prepare('SELECT * FROM student WHERE AdvID=:id');
$query->bindParam(":id",$_SESSION['userid']);
$query->execute();
$row = $query->fetch();
while($row = $query->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td> <input type ="checkbox" name="checked[]" value="<?php echo $row['StuId'];?>"> </td>
<td><?php echo $row['StuId']; ?></td>
<td><?php echo $row['Name']; ?></td>
<td> </td>
<td>
<button type="submit" name="submit" value="<?php echo $row['StuId'];?>" class="btn icon-btn btn-info" ><span class="glyphicon glyphicon-info-sign"></span>More Information</button>
</td>
</tr>
<?php
}
do {
while ($query->fetch())
;
if (!$query->nextRowset())
break;
} while (true);
$conn=null;
$query->closeCursor();
?>
</table>
</form>
<?php
if (isset($_GET['submit'])){
global $CC;
$count=1;
global $data;
$T=$_GET['submit'];
?>
<script>
$('#CC').html("");
$('#CC1').html("");
</script>
<?php
require('check.php');
$q= $conn->prepare('SELECT CouID FROM CoursesC WHERE StuID = :ID ');
$q->bindValue(':ID', $_GET['submit']);
$q->execute();
$data = $q->fetch();
while($data = $q->fetch(PDO::FETCH_ASSOC)){
$CC=$data['CouID'];
?>
<script>
$('#CC').append("<option><? echo $count++; echo "- "; echo $CC;?></option>");
</script>
<?php
}
$q->closeCursor();
$A=$CC;
/*echo "<script> alert('<?php $T ?>')";*/
$q1= $conn->prepare('SELECT CouID FROM Courses');
$q1->execute();
$data1 = $q1->fetch();
while($data1 = $q1->fetch(PDO::FETCH_ASSOC)){
if($CC!=$data1['CouID']){
?>
<script>
$('#CC1').append("<option><? echo $count++; echo "- "; echo $data1['CouID'];?></option>");
</script>
<?php
}
}
$q1->closeCursor();
?>
<script>
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
<?
}
?>
<?php
if (isset($_GET['submit'])){
global $CC;
$count=1;
global $data;
$T=$_GET['submit'];
?>
<script>
$('#CC').html("");
$('#CC1').html("");
</script>
<?php
require('check.php');
$q= $conn->prepare('SELECT CouID FROM CoursesC WHERE StuID = :ID ');
$q->bindValue(':ID', $_GET['submit']);
$q->execute();
$data = $q->fetch();
while($data = $q->fetch(PDO::FETCH_ASSOC)){
$CC=$data['CouID'];
?>
<script>
$('#CC').append("<option><? echo $count++; echo "- "; echo $CC;?></option>");
</script>
<?php
}
$q->closeCursor();
$A=$CC;
/*echo "<script> alert('<?php $T ?>')";*/
$q1= $conn->prepare('SELECT CouID FROM Courses');
$q1->bindParam(":id", $_GET['submit']);
$q1->execute();
$data1 = $q1->fetch();
while($data1 = $q1->fetch(PDO::FETCH_ASSOC)){
if($CC!=$data1['CouID']){
?>
<script>
$('#CC1').append("<option><? echo $count++; echo "- "; echo $data1['CouID'];?></option>");
</script>
<?php
}
}
$q1->closeCursor();
?>
<script>
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
<?
}
?>
<?php
if (isset($_GET['submit'])){
global $CC;
$count=1;
global $data;
$T=$_GET['submit'];
?>
<script>
$('#CC').html("");
$('#CC1').html("");
</script>
<?php
require('check.php');
$q= $conn->prepare('SELECT CouID FROM CoursesC WHERE StuID = :ID ');
$q->bindValue(':ID', $_GET['submit']);
$q->execute();
$data = $q->fetch();
while($data = $q->fetch(PDO::FETCH_ASSOC)){
$CC=$data['CouID'];
?>
<script>
$('#CC').append("<option><? echo $count++; echo "- "; echo $CC;?></option>");
</script>
<?php
}
$q->closeCursor();
$A=$CC;
/*echo "<script> alert('<?php $T ?>')";*/
$q1= $conn->prepare('SELECT CouID FROM Courses');
$q1->bindParam(":id", $_GET['submit']);
$q1->execute();
$data1 = $q1->fetch();
while($data1 = $q1->fetch(PDO::FETCH_ASSOC)){
if($CC!=$data1['CouID']){
?>
<script>
$('#CC1').append("<option><? echo $count++; echo "- "; echo $data1['CouID'];?></option>");
</script>
<?php
}
}
$q1->closeCursor();
?>
<script>
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
<?
}
?>
您好,您的問題非常廣泛,當您說「查詢」時,您需要明確哪些查詢,在您的代碼中有很多查詢。如果你很具體會更容易幫助你。 –
@PabloCesarCordovaMorales對不起,我已更新我的評論它的第一個查詢,我認爲問題在$ q-> bindValue,因爲當我刪除它的工作,但我需要它獲得用戶的價值 –
':ID'和':ID'是兩種不同的動物,但你沒有用'$ q1 = $ conn-> prepare('SELECT CouID FROM Courses')做任何事情; $ q1-> bindParam(「:id」,$ _GET ['submit']);'在沒有綁定,不知道你爲什麼使用提交作爲參考。 –