gpt4 book ai didi

php - 通过 PHP 调用 SQL,选择所有命令但缺少 1 个结果?

转载 作者:行者123 更新时间:2023-11-29 02:56:51 25 4
gpt4 key购买 nike

基本上,我有一个使用 SQL 来检查是否选择了任何 ID 的 PHP 网页。如果不是,它会自动选择日期为 2015 的所有结果。但是第一个结果总是丢失。通过阅读其他帖子,我只能假设我的 select all $result 从 1 开始,即使表中的数据从 0 开始。要么,要么我的代码的某些部分正在吃掉第一个结果。如有任何帮助,我们将不胜感激。

if (isset($_GET["id"])){$id=$_GET["id"];}else{$id="";}

if ($id==""){
$select ="select * from organicgrants where lastupdated > '2015'";

$result = mysql_query($select);
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
$organicgrantsid=$row["organicgrantsid"];
$firstname=$row["teacherfirstname"];
$lastname=$row["teacherlastname"];
$lastupdated=date('F j, Y', strtotime($row["lastupdated"]));

echo ("<p>");
echo("<p><b>Total Applications Displayed: ".mysql_num_rows($result)."</b></p>");
echo ("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">");
echo ("<tr bgcolor=\"#cccccc\"><td><Strong>Teacher Name</td><td><Strong>School Name</td><td><Strong>State</td><td><Strong>Grade(s)</td><td><Strong>Submitted Date</td>
<td><Strong>Status</td></Strong></tr>");

while ( $row = mysql_fetch_array($result) ) {;
$organicgrantsid=$row["organicgrantsid"];
$teacherfirstname=$row["teacherfirstname"];
$teacherlastname=$row["teacherlastname"];
$schoolname=$row["schoolname"];
$schoolstate=$row["schoolstate"];
$gradelevels=$row["gradelevels"];
$lastupdated=$row["lastupdated"];
$grantstatus=$row["grantstatus"];
//$staffawarded=$row["staffawarded"];
//$staffconference=$row["staffconference"];

switch ($grantstatus){
case "":
$grantstatus="Waiting List";
break;
case "0":
$grantstatus="Waiting List";
break;
case "1":
$grantstatus="Awarded";
break;
case "2":
$grantstatus="Not Awarded";
break;
}

$lastupdated=date('F j, Y', strtotime($row["lastupdated"]));
echo ("<tr><td><a href=\"results.php?id=".$organicgrantsid."\">".$teacherfirstname." ".$teacherlastname."</a></td><td>".$schoolname."</td><td>".$schoolstate."</td><td>".$gradelevels."</td><td>(".$lastupdated.")</td><td>".$grantstatus."</td></tr>");

}
echo ("</table>");
}
}else{

$select ="select * from organicgrants where organicgrantsid=$id";

$result = mysql_query($select);
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
$schoolname=$row["schoolname"];
$schooladdress=$row["schooladdress"];
$schoolcity=$row["schoolcity"];
$schoolstate=$row["schoolstate"];
$schoolzip=$row["schoolzip"];
$schoolphone=$row["schoolphone"];
$schoolcounty=$row["schoolcounty"];
$gradelevelsitem=$row["gradelevels"];
$teacherfirstname=$row["teacherfirstname"];
$teacherlastname=$row["teacherlastname"];
$teacherposition=$row["teacherposition"];
$teacheremail=$row["teacheremail"];
$teacherphone=$row["teacherphone"];
$numberofstudents=$row["numberofstudents"];
$budgetA=$row["budgetA"];
$budgetB=$row["budgetB"];
$budgetC=$row["budgetC"];
$budgetD=$row["budgetD"];
$budgetE=$row["budgetE"];
$budgetF=$row["budgetF"];
$budgetG=$row["budgetG"];
$budgetI=$row["budgetI"];
$budgetJ=$row["budgetJ"];
$budgetK=$row["budgetK"];
$budgetAamt=$row["budgetAamt"];
$budgetBamt=$row["budgetBamt"];
$budgetCamt=$row["budgetCamt"];
$budgetDamt=$row["budgetDamt"];
$budgetEamt=$row["budgetEamt"];
$budgetFamt=$row["budgetFamt"];
$budgetGamt=$row["budgetGamt"];
$budgetHamt=$row["budgetHamt"];
$budgetIamt=$row["budgetIamt"];
$budgetJamt=$row["budgetJamt"];
$budgetKamt=$row["budgetKamt"];
$budgetLamt=$row["budgetLamt"];
$budgetMamt=$row["budgetMamt"];
$essayimportant=$row["essayimportant"];
$essaybenefit=$row["essaybenefit"];
$essayexperience=$row["essayexperience"];
$essaybeneficial=$row["essaybeneficial"];
$supportingfunds=$row["supportingfunds"];
$principalname=$row["principalname"];
$principalemail=$row["principalemail"];
$grantstatus=$row["grantstatus"];
$w9status=$row["w9status"];
$agreementstatus=$row["agreementstatus"];
$progressstatus=$row["progressstatus"];
$finalstatus=$row["finalstatus"];
$receiptsstatus=$row["receiptsstatus"];
$staffstatus=$row["staffstatus"];
$imisstatus=$row["imisstatus"];

$schooladmin=$row["schooladmin"];
if ($schooladmin==1){$schooladmin="Yes";}else{$schooladmin="No";}
$w9form=$row["w9form"];
if ($w9form==1){$w9form="Yes";}else{$w9form="No";}
$gradelevelsitem="";
if (isset($_POST['gradelevels'])==true){$gradelevels=$_POST['gradelevels'];foreach ($gradelevels as $key => $value )$gradelevelsitem.="$value, ";}
$gradelevelsitem=substr($gradelevelsitem,0,(strlen($gradelevelsitem)-2));`

最佳答案

两个 while 循环的目的是什么(除了窃取您的第一个 row – 在内部循环中,您重新分配$row 来自外循环第一次迭代的变量)?移动第一个 while 循环中的所有分配/输出并删除第二个循环(您缺少大括号 {} 所以我猜这是一个内部循环)。

而不是这个:

while ( $row = mysql_fetch_array($result) ) {
$organicgrantsid=$row["organicgrantsid"];
$firstname=$row["teacherfirstname"];
$lastname=$row["teacherlastname"];
$lastupdated=date('F j, Y', strtotime($row["lastupdated"]));

echo ("<p>");
echo("<p><b>Total Applications Displayed: ".mysql_num_rows($result)."</b></p>");
echo ("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">");
echo ("<tr bgcolor=\"#cccccc\"><td><Strong>Teacher Name</td><td><Strong>School Name</td><td><Strong>State</td><td><Strong>Grade(s)</td><td><Strong>Submitted Date</td><td><Strong>Status</td></Strong></tr>");

while ( $row = mysql_fetch_array($result) ) {;
$organicgrantsid=$row["organicgrantsid"];
$teacherfirstname=$row["teacherfirstname"];
$teacherlastname=$row["teacherlastname"];
$schoolname=$row["schoolname"];
$schoolstate=$row["schoolstate"];
$gradelevels=$row["gradelevels"];
$lastupdated=$row["lastupdated"];
$grantstatus=$row["grantstatus"];
//$staffawarded=$row["staffawarded"];
//$staffconference=$row["staffconference"];

switch ($grantstatus){
case "":
$grantstatus="Waiting List";
break;
case "0":
$grantstatus="Waiting List";
break;
case "1":
$grantstatus="Awarded";
break;
case "2":
$grantstatus="Not Awarded";
break;
}

$lastupdated=date('F j, Y', strtotime($row["lastupdated"]));
echo ("<tr><td><a href=\"results.php?id=".$organicgrantsid."\">".$teacherfirstname." ".$teacherlastname."</a></td><td>".$schoolname."</td><td>".$schoolstate."</td><td>".$gradelevels."</td><td>(".$lastupdated.")</td><td>".$grantstatus."</td></tr>");
}
echo ("</table>");
}

使用这个:

echo ("<p>");                       
echo("<p><b>Total Applications Displayed: ".mysql_num_rows($result)."</b></p>");
echo ("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">");
echo ("<tr bgcolor=\"#cccccc\"><td><Strong>Teacher Name</td><td><Strong>School Name</td><td><Strong>State</td><td><Strong>Grade(s)</td><td><Strong>Submitted Date</td><td><Strong>Status</td></Strong></tr>");

while ( $row = mysql_fetch_array($result) ) {
$organicgrantsid=$row["organicgrantsid"];
$firstname=$row["teacherfirstname"];
$lastname=$row["teacherlastname"];
$lastupdated=date('F j, Y', strtotime($row["lastupdated"]));
$organicgrantsid=$row["organicgrantsid"];
$teacherfirstname=$row["teacherfirstname"];
$teacherlastname=$row["teacherlastname"];
$schoolname=$row["schoolname"];
$schoolstate=$row["schoolstate"];
$gradelevels=$row["gradelevels"];
$lastupdated=$row["lastupdated"];
$grantstatus=$row["grantstatus"];
//$staffawarded=$row["staffawarded"];
//$staffconference=$row["staffconference"];

switch ($grantstatus){
case "":
$grantstatus="Waiting List";
break;
case "0":
$grantstatus="Waiting List";
break;
case "1":
$grantstatus="Awarded";
break;
case "2":
$grantstatus="Not Awarded";
break;
}

$lastupdated=date('F j, Y', strtotime($row["lastupdated"]));
echo ("<tr><td><a href=\"results.php?id=".$organicgrantsid."\">".$teacherfirstname." ".$teacherlastname."</a></td><td>".$schoolname."</td><td>".$schoolstate."</td><td>".$gradelevels."</td><td>(".$lastupdated.")</td><td>".$grantstatus."</td></tr>");
}
echo ("</table>");

关于php - 通过 PHP 调用 SQL,选择所有命令但缺少 1 个结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29906948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com