/    Sign up×
Community /Pin to ProfileBookmark

Different results in different browsers

Hi
The code below is a part of school site where parents get their kids grades. Recently I noticed that on some computers, the grade list is empty as if there is a connection problem with the database. On the same PC, Firefox has no issues, while IE has the problem mentioned. At my home PC, I have no problem wiht IE or Chrome showing the results!

I would appreciate if someone could help me understand why browsers are coming up with different results.

thanks in advance.

$user =& JFactory::getUser();
$session =& JFactory::getSession();
$session->set(‘username’, $user->get(‘username’));

$session =& JFactory::getSession();

mysql_connect (“SERVER” , “LOGIN” , “PASSWORD” ) or die(mysql_error());
mysql_select_db(“joomla_joomla”) or die(mysql_error());

$mytest = mysql_query(“select students.fname, students.lname, students.logname, students.year from students where students.logname = ‘”.$session->get(‘username’).”‘;” )
or die(mysql_error());

echo “Results<br><br>”;
while($info1 = mysql_fetch_array( $mytest ))
{
print “<tr>Student: <td> “.$info1[‘fname’].” </td> <td>”.$info1[‘lname’] .” </td> — Grade <td>”.$info1[‘year’] .” </td></tr>”;
}
?>

<br><br>
</center></b>
<table align=”center”>
<?php
//connect to db
mysql_connect (“SERVER” , “LOGIN” , “PASSWORD” ) or die(mysql_error());
mysql_select_db(“joomla_joomla”) or die(mysql_error());
//SET NAMES ‘utf8’;
//collect data
$data = mysql_query(“select grades.term, grades.subject, grades.grade, students.fname, students.lname, students.logname, students.st_id, grades.st_id from grades, students where students.st_id=grades.st_id and grades.term=’1′ and students.logname = ‘”.$session->get(‘username’).”‘;” )
or die(mysql_error());

Print “<table border cellpadding=5>”;
print “<th bgcolor=#B6BA18><font size=’3′>Grade</th>”;
print “<th bgcolor=#B6BA18><font size=’3′>Subject</th>”;
echo “$info[fname]”;
while($info = mysql_fetch_array( $data ))

{

print “<tr>”;

print “<tr><td div align=center width=”135″ height=”2”><font size=’2′> “.$info[‘grade’].” </td></font> <td div align=right><font size=’2′>”.$info[‘subject’] .” </td></font></tr>”;

}

Print “</table>”
?>
</table>

</p>
</blockquote>
</blockquote>

</blockquote>
</blockquote>

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bionoidFeb 01.2012 — Wow, there are so many errors in this small section of code, where to begin?

There are tag attributes that are specified without values, and some tags are not even being closed:

[CODE][COLOR="Red"]Print[/COLOR] "<table [COLOR="red"]border[/COLOR] cellpadding=5>";
print "<th bgcolor=#B6BA18>[COLOR="red"]<font size='3'>[/COLOR]Grade</th>";
print "<th bgcolor=#B6BA18[COLOR="red"]><font size='3'>[/COLOR]Subject</th>";[/CODE]


... could be written like ...

[code=php]echo
'<table border="1" cellpadding="5">' .
'<th bgcolor="#B6BA18"><font size="3">Grade</font></th>' .
'<th bgcolor="#B6BA18"><font size="3">Subject</font></th>';[/code]


You have data being written randomly (reformated), where there are no valid tags open:

[CODE]echo $info['fname'];[/CODE]

Some tags are being opened needlessly, and contain bad attributes. Some are also being closed in the incorrect order:

[CODE][COLOR="red"]print "<tr>";[/COLOR]

print "<tr><td [COLOR="red"]div[/COLOR] align=center width="135" height="2">[COLOR="red"]<font size='2'>[/COLOR] ".$info['grade']." </td>[COLOR="red"]</font>[/COLOR] <td [COLOR="red"]div[/COLOR] align=right>[COLOR="red"]<font size='2'>[/COLOR]".$info['subject'] ." </td>[COLOR="red"]</font>[/COLOR]</tr>";[/CODE]


... could be written like ...

[code=php]echo
'<tr>' .
'<td align="center" width="135"><font size="2">' . $info['grade'] . '</font></td>' .
'<td align="right"><font size="2">' . $info['subject'] . '</font></td>' .
'</tr>';[/code]


The database is also being opened more than once where you could just use the previous connection (assuming that this code all sits in the same script file).

Using a stylesheet instead of writing inline styles would clean up the code considerably, but it shouldn't break anything the way it is.

There are other problems in the code, but this is a good starting point.

If you want to check for errors, validate the output of your script here: http://validator.w3.org/

Good Luck.
Copy linkTweet thisAlerts:
@mehranalmasiauthorFeb 01.2012 — Thanks bionoid for your points. I will put them to work. Do you think the problem I mentioned is rooted at problems you mention? I am confused why this messy code works in my PC's IE and Chrome but not in IE on another PC and on the same PC works with Firefox! Do you have any idea?
Copy linkTweet thisAlerts:
@NogDogFeb 01.2012 — When you have invalid [X]HTML mark-up, the browser is forced to either guess what you meant or to ignore things it cannot parse. How each particular browser will guess or whether it will ignore in any given case is not standardized, so you cannot predict ahead of time how any particular browser will react.

Therefore, even though a given web page may work okay in spite of having invalid HTML, it is still in your best interest to remove [i]all[/i] [X]HTML mark-up errors so that you do not have to worry (much) about browsers you have not tested it in.
×

Success!

Help @mehranalmasi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...