mysql — вызывает SQL через PHP, выбирает все команды, но отсутствует 1 результат?

В общем, у меня есть веб-страница PHP с использованием SQL, чтобы проверить, выбран ли какой-либо идентификатор. Если это не так, он автоматически выбирает все результаты с датой 2015 года. Однако 1-й результат всегда отсутствует. Читая другие посты, я могу только предположить, что мой результат 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));`

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>");
1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]