Jump to content

If statement not functioning properly?? Help?


Round

Recommended Posts

I have two tables in the db and I want the site to query one of the tables first and display the records, If the first query doesn't return any results I want another query to be executed against another table and display, but if that query doesn't return any results then just display a message.

I have manged to get it to query and display records from the first table, it will also query and display the records from the second table if the first query doesn't return any results. Even when both queries do not return any results the message [b]is[/b] getting displayed but all of the other information on the site is then not displaying after the message.

[code]<?php
  #connect to db
$conn = @mysql_connect(  "localhost", "username", "password" )
      or die( "Err:conn");
#select db
$rs = @mysql_select_db( "dbname", $conn)
or die( "ERR:Db");

#create query
$sql = "select * from stu_details where stu_id=\"$stu_id\" ";

$sql4 = "select * from assess_06 where stu_id=\"$stu_id\" ";

#exe query
$rs4 = mysql_query( $sql4, $conn )
or die( "Could not execute Query");



$num4 = mysql_numrows ($rs4);
if ($num4 !=0)
{
$list4 = "<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">";
$list4 .= "<tr>";
$list4 .= "<th class=table>Date/Year</th>";
$list4 .= "<th class=table>Assessment</th>";
$list4 .= "<th class=table>Result</th>";
$list4 .= "<th class=table>Result Notes</th>";
$list4 .= "<th class=table>Suggestion</th>";
$list4 .= "</tr>";

#retrieve data
while ( $row4 = mysql_fetch_array( $rs4 ) )
{
$list4 .= "<tr>";
$list4 .= "<td class=table>".$row4["acadyear"]."</td>";
$list4 .= "<td class=table>".$row4["subject"]."</td>";
$list4 .= "<td class=table>".$row4["result"]."</td>";
$list4 .= "<td class=table>".$row4["resultnotes"]."</td>";
$list4 .= "<td class=table>".$row4["suggestion"]."</td>";
$list4 .= "</tr>";
}
$list4 .= "</table>";

echo( $list4. "<br>" );
}
else
{
#create query
$sql5 = "select * from assess_05 where student_id=\"$student_id\" ";

#exe query
$rs5 = mysql_query( $sql5, $conn )
or die( "Could not execute Query");

$num5 = mysql_numrows ($rs5);
if ($num5 !=0)
{
while ( $row5 = mysql_fetch_array( $rs5 ) )
{
$list5 = "<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">";
$list5 .= "<tr>";
$list5 .= "<th class=table>Date/Year</th>";
$list5 .= "<th class=table>Assessment</th>";
$list5 .= "<th class=table>Result</th>";
$list5 .= "<th class=table>Result Notes</th>";
$list5 .= "</tr>";
$list5 .= "<tr>";
$list5 .= "<td class=table>".$row5["acadyear"]."</td>";
$list5 .= "<td class=table>".$row5["subject"]."</td>";
$list5 .= "<td class=table>".$row5["result"]."</td>";
$list5 .= "<td class=table>".$row5["resultnotes"]."</td>";
$list5 .= "</tr>";
}
$list5 .= "</table>";

echo( $list5. "<br>" );
}
else
{ echo ("<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">
<tr>
<th class=table>There are no Initial Assessment results for this Learner</th>
</tr>
</table>");
{
exit();}
exit();}
}
?>
<table align=center border=0 width=525>
<tr>
<th class=table colspan=2>Diagnostic Tests</th>
</tr>
<tr>
<td class=table width=250><br><form action="my_diaglit.php"><input type="submit" value="Literacy results"></form></td>
<td class=table><br><form action="my_diagnum.php"><input type="submit" value="Numeracy results"></form></td>
</tr>
</table>
<br>
<?php

#exe query
$rs6 = mysql_query( $sql, $conn )
or die( "Could not execute Query");

while ( $row6 = mysql_fetch_array( $rs6 ) )
{
$list6 = "<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">";
$list6 .= "<tr>";
$list6 .= "<th class=table>What issues do I need to look at that may affect my learning</th>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "<td class=table>".$row6["learn_issues"]."</td>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "<th class=table>Where do I want to go after completing this course?</th>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "<td class=table>".$row6["post_course"]."</td>";
$list6 .= "</tr>";
}
$list6 .= "</table>";

echo( $list6. "<br>" );
?>[/code]

All of the stuff after the first chunk of php code displays fine if it finds results in the first table, it even displays fine if the first table is empty and  displays the results from the second table, but if it doesn't find any results from either table and then displays the message:- [b]There are no Initial Assessment results for this Learner[/b]

The following disapears from the page ???:-

[code]<table align=center border=0 width=525>
<tr>
<th class=table colspan=2>Diagnostic Tests</th>
</tr>
<tr>
<td class=table width=250><br><form action="my_diaglit.php"><input type="submit" value="Literacy results"></form></td>
<td class=table><br><form action="my_diagnum.php"><input type="submit" value="Numeracy results"></form></td>
</tr>
</table>
<br>
<?php

#exe query
$rs6 = mysql_query( $sql, $conn )
or die( "Could not execute Query");

while ( $row6 = mysql_fetch_array( $rs6 ) )
{
$list6 = "<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">";
$list6 .= "<tr>";
$list6 .= "<th class=table>What issues do I need to look at that may affect my learning</th>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "<td class=table>".$row6["learn_issues"]."</td>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "<th class=table>Where do I want to go after completing this course?</th>";
$list6 .= "</tr>";
$list6 .= "<tr>";
$list6 .= "<td class=table>".$row6["post_course"]."</td>";
$list6 .= "</tr>";
}
$list6 .= "</table>";

echo( $list6. "<br>" );
?>[/code]

Hope this all makes sense and I hope some one can help.

Many thanks

(p.s. other queries exist in page hence strange names like rs6 etc)
Link to comment
Share on other sites

I think I may have solved it sometimes you just can't see for looking!!, However I won't edit the topic as solved just yet as someone may still find a fault with my solution.
any way here is my solution,

I changed this:-

[code]else
{ echo ("<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">
<tr>
<th class=table>There are no Initial Assessment results for this Learner</th>
</tr>
</table>");
{
exit();}
exit();}
}
?>[/code]

to this:-

[code]else
{ echo ("<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"525\">
<tr>
<th class=table>There are no Initial Assessment results for this Learner</th>
</tr>
</table>");
}}
?>[/code]

It clearly didn't like the exits.
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.