Baltimore PHP Message Board › Hiding rows in php

Hiding rows in php

James
user 53210412
Baltimore, MD
Post #: 1
Please i need help concerning this code. I want to hide rows whose total is zero. Once a row have zero as value for total i want it hidden. I need this assistance asap. Thank you




$query = "SELECT * FROM firsttermsar
WHERE studentID=$stuID AND year=\"$_SESSION[year]\"";­ #27
$result = mysql_query($query)
or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<h2> FIRST TERM RESULT for $namet during the SESSION $year</h2>";
echo "<table class='table1'>";

echo "<tr>";
echo "<td><b>Mark Obtainable</b></td>";
echo "<td><b>CA(30)</b>­</td>
<td><b>Exam</b></­td> <td><b>Total(70)</b><­/td><td><b>Grade</b>­</td><td><b>Comment<­/b></td><td><b>Teac­her's Signature</b></td></tr>­";
if ($total>="1")
echo "<td>English Language: </td>";
echo "<td>{$row['firstengtest']}<­/td> <td>{$row['firstengexam']}</td>­ <td>";
$total = $row['firstengtest']+$row['firstengexam'­];
echo $total."</td><td>";­

if ($total>="70")
echo "A ";
elseif ($total>="60")
echo "B";
elseif ($total>="50")
echo "C";
elseif ($total>="40")
echo "D";
elseif ($total>="30")
echo "E";
elseif ($total=="0")
echo "-";
else
echo "F";


echo "</td><td> </td> <td>";
if ($total>="70")
echo "EXCELLENT";
elseif ($total>="60")
echo "VERY GOOD";
elseif ($total>="50")
echo "GOOD";
elseif ($total>="40")
echo "PASS";
elseif ($total>="30")
echo "POOR";
elseif ($total=="0")
echo "-";
else
echo "FAIL";
echo "</td></tr>";

echo "<tr>";
echo "<td>Mathematics </td>";
echo "<td>{$row['firstmathtest']}<­/td> <td>{$row['firstmathexam']}</td­> <td>";
$total = $row['firstmathtest']+$row['firstmathexa­m'];
echo $total."</td><td>";­

if ($total>="70")
echo "A";
elseif ($total>="60")
echo "B";
elseif ($total>="50")
echo "C";
elseif ($total>="40")
echo "D";
elseif ($total>="30")
echo "E";
elseif ($total=="0")
echo "-";
else
echo "F";



echo "</td><td> </td> <td>";
if ($total>="70")
echo "EXCELLENT";
elseif ($total>="60")
echo "VERY GOOD";
elseif ($total>="50")
echo "GOOD";
elseif ($total>="40")
echo "PASS";
elseif ($total>="30")
echo "POOR";
elseif ($total=="0")
echo "-";
else
echo "FAIL";
echo "</td></tr>";

echo "<tr>";
echo "<td>Physics: </td>";
echo "<td>{$row['firstphytest']}<­/td> <td>{$row['firstphyexam']}</td>­ <td>";
$total = $row['firstphytest']+$row['firstphyexam'­];
echo $total."</td><td>";­

if ($total>="70")
echo "A";
elseif ($total>="60")
echo "B";
elseif ($total>="50")
echo "C";
elseif ($total>="40")
echo "D";
elseif ($total>="30")
echo "E";
elseif ($total=="0")
echo "-";
else
echo "F";


echo "</td><td> </td> <td>";
if ($total>="70")
echo "EXCELLENT";
elseif ($total>="60")
echo "VERY GOOD";
elseif ($total>="50")
echo "GOOD";
elseif ($total>="40")
echo "PASS";
elseif ($total>="30")
echo "POOR";
elseif ($total=="0")
echo "-";
else
echo "FAIL";
echo "</td></tr>";

echo "<tr>";
echo "<td>Chemistry: </td>";
echo "<td>{$row['firstchemtest']}<­/td> <td>{$row['firstchemexam']}</td­> <td>";
$total = $row['firstchemtest']+$row['firstchemexa­m'];
echo $total."</td><td>";­

if ($total>="70")
echo "A";
elseif ($total>="60")
echo "B";
elseif ($total>="50")
echo "C";
elseif ($total>="40")
echo "D";
elseif ($total>="30")
echo "E";
elseif ($total=="0")
echo "-";
else
echo "F";



echo "</td><td> </td> <td></td></tr>";
Trevor G.
tgryffyn
Edgewater, MD
Post #: 2
Two ways you could do it. First, exclude the rows using the SQL statement you're using. The other would be to check the value of $total and only echo out the data if $total >= 0. It looks like that's what you're trying to do but your if() statement is incomplete.

You have:
if ($total >= "1")

without {} to enclose what to do IF that statement is true, it will only execute the next line. So what you're doing there is only echoing "<td>English Language</td>" if $total >= 1. You want to enclose all your echo statements in {} to do what you want.

If you want to just do it with SQL, remove that if($total>="1") statement and change your SQL to this:

$query = "SELECT * FROM firsttermsar WHERE studentID=$stuID AND year=\"$_SESSION[year]\" AND firstengtest + firstengexam > 0";


As a side note, it's a good idea to sanitize the data in your SQL statement to ward against SQL Injection attacks. For numer ID's, a simple intval($var) ensures only numeric/integer values go into the SQL. For string data, you want to use mysql_real_escape_string($var) at the very least (simplest change to achieve some level of security).

So your query would end up being something like:

$query = "SELECT * FROM firsttermsar WHERE studentID = " . intval($stuID) . " AND year = '" . mysql_real_escape_string($_SESSION['year­']) . "' AND firstengtest + firstengexam > 0;";

James
user 53210412
Baltimore, MD
Post #: 2
Pro. Thanks so much for your help. It work out as you've tutor. Have a great day and thanks for your help.
You just saved me and my entire team from a mess. Meet u at the top.
Trevor G.
tgryffyn
Edgewater, MD
Post #: 3
Pro. Thanks so much for your help. It work out as you've tutor. Have a great day and thanks for your help.
You just saved me and my entire team from a mess. Meet u at the top.

No problem, James. Let me know if you run into any other problems that I might be able to help with.

-Trevor
James
user 53210412
Baltimore, MD
Post #: 4
Hello again, please i need help with creating position for the student in my dbase project. I have two tables (1) is Student table and the other (2) is result table called thirdtermsar.

Student table
Id | name | class
1 | sharon t. | Js 1
2 | Didier L. | Js 2
3 | Peep | Js 2
4 | Bill G. | Js 1
5 | Leech Y. | Js 3


thirdtermsar table
student id |engtest | engexam | mathtest | mathexam
1 | 10 | 60 | 25 | 67
2 | 26 | 45 | 16 |45
3 | 15 | 56 | - | -
4 | 17 | 67 | 13 |61
5 | 30 | 46 | 20 |58

Please i want to group by class and assign position to individual student by class (test)+(exam) = $(total)
so for Js 1 student ID 4 takes the 1st position in english language with 84marks.

Please I need help this project is my life. kindly help me if u got the solution and already i have the following to display the result.

$query = "SELECT * FROM thirdtermsar
WHERE studentID=$stuID AND year=\"$_SESSION[year]\"";­ #27
$result = mysql_query($query)
or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<table class='table1'>";
echo "<tr>";
echo "<td></td>";
echo "<td>1st Term<br />Total Score</td><td>2nd Term<br />Total Score</td><td>3rd Term<br />CA</td>
<td>3rd Term<br />Exam</td><td>3rd Term<br />Total<td>Annual<br />Total </td><td>Annual<br />Average</td><td>Grade<­br />Point</td><td> Teacher's<br />Signature</td><td>Comme­nt</td></tr>";
echo "<tr> <td><b>Mark Obtainable</b></td><td>­<b>100</b></td><td>­<b>100</b></td><td>­<b>30</b></td><td>­<b>70</b></td><td>­<b>100</b></td><td>­<b>300</b></td><td>­<b>%</b></td><td>­<b>||=||</b></td><t­d></td><td><b>||=||­</b></td></tr><tr>­";

$tetal = $row['thirdengtest']+$row['thirdengexam'­]+$row['eng1']+$row['eng2'];
if ($tetal >="1") {
echo "<td>English Language: </td>";
echo "<td>{$row['eng1']}</td>­<td>{$row['eng2']}</td><t­d>{$row['thirdengtest']}</td> <td>{$row['thirdengexam']}</td>­ <td>";
$total = $row['thirdengtest']+$row['thirdengexam'­];
echo $total."</td><td>";­
$tetal = $row['thirdengtest']+$row['thirdengexam'­]+$row['eng1']+$row['eng2'];
echo $tetal."</td><td>";­
$tetals = round($tetal/3);
echo $tetals."</td><td>";­

if ($total>="70")
echo "A";
elseif ($total>="60")
echo "B";
elseif ($total>="50")
echo "C";
elseif ($total>="40")
echo "D";
elseif ($total>="30")
echo "E";
elseif ($total=="0")
echo "-";
else
echo "F";



echo "</td><td> </td> <td>";
if ($total>="70")
echo "EXCELLENT";
elseif ($total>="60")
echo "VERY GOOD";
elseif ($total>="50")
echo "GOOD";
elseif ($total>="40")
echo "PASS";
elseif ($total>="30")
echo "POOR";
elseif ($total=="0")
echo "-";
else
echo "FAIL";
echo "</td></tr>";
}

$tetal = $row['thirdmathtest']+$row['thirdmathexa­m']+$row['math1']+$row['math2'];
if ($tetal >="1") {
echo "<tr>";
echo "<td>Mathematics </td>";
echo "<td>{$row['math1']}</td>­<td>{$row['math2']}</td><­td>{$row['thirdmathtest']}</td>­ <td>{$row['thirdmathexam']}</td­> <td>";
$total = $row['thirdmathtest']+$row['thirdmathexa­m'];
echo $total."</td><td>";­
$tetal = $row['thirdmathtest']+$row['thirdmathexa­m']+$row['math1']+$row['math2'];
echo $tetal."</td><td>";­
$tetals = round($tetal/3);
echo $tetals."</td><td>";­

if ($total>="70")
echo "A";
elseif ($total>="60")
echo "B";
elseif ($total>="50")
echo "C";
elseif ($total>="40")
echo "D";
elseif ($total>="30")
echo "E";
elseif ($total=="0")
echo "-";
else
echo "F";


echo "</td><td> </td> <td>";
if ($total>="70")
echo "EXCELLENT";
elseif ($total>="60")
echo "VERY GOOD";
elseif ($total>="50")
echo "GOOD";
elseif ($total>="40")
echo "PASS";
elseif ($total>="30")
echo "POOR";
elseif ($total=="0")
echo "-";
else
echo "FAIL";
echo "</td></tr>";
}
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy