Hi there, this is my first post here (though I've found several answers to previous problems here by searching).
I have a script that I wrote that is pulling data from a DB. My script works fine for pulling the data from the DB and displaying it, actually, the output is displayed correctly in Firefox (1.5 - 3.0.3) but there is a large gap between the Header (which is the job title) and the listing JobTitle when viewed in IE6 (I think it works fine in IE7 but since I am on Linux I can't check that right now - I'm looking for a fix on that issue..)
So, I'm looking for suggestions on how I can make this script more efficient. Here is the code:
PHP Code:
$result = @mysql_query("SELECT * FROM $db_table ORDER BY id DESC"); if (!$result) { exit("<p>Error performing query: " . mysql_error() . "</p>"); } elseif (mysql_num_rows($result) == 0){ echo "<h4>Sorry, there are no job listings at this time.</h4>"; } else { while ($row = mysql_fetch_array($result)) { $id = $row['id']; $jobtitle = $row['title']; $empl = $row['employer']; $loc = $row['location']; $fte = $row['fte']; $shift = $row['shift']; $salary = $row['salary']; $desc = $row['description']; $quals = $row['qualifications']; $prefd = $row['preferred']; $howto = $row['howtoapply']; $url = $row['url']; $contName = $row['contactname']; $contPhone = $row['contactphone']; $contEmail = $row['contactemail']; $added = date("m/d/y", strtotime($row['added'])); // change all HTML special characters, // to prevent some nasty code injection $desc = htmlspecialchars($desc); $quals = htmlspecialchars($quals); $prefd = htmlspecialchars($prefd); $howto = htmlspecialchars($howto); // convert newline characters to HTML break tag ( <br /> ) $desc = nl2br($desc); $quals = nl2br($quals); $prefd = nl2br($prefd); $howto = nl2br($howto); echo "<h3>".$jobtitle."</h3>"."\n"; //table format echo "<table width=\"600\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\" class=\"jobs\" summary=\"This table lists all of the available jobs listed with the Washington State Biomedical Association in the Northwestern region of the United States.\">"."\n"; echo "<tr class=\"jobs\" valign=\"top\"><td width=\"110\"><strong>Title:</strong></td><td width=\"490\">".$jobtitle."</td></tr>"."\n"; echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Employer:</strong></td><td class=\"jobs\">".$empl."</td></tr>"."\n"; if ($loc !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Location:</strong></td><td class=\"jobs\">".$loc."</td></tr>"."\n"; } if ($fte !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>FTE:</strong></td><td class=\"jobs\">".$fte."</td></tr>"."\n"; } if ($shift !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Shift:</strong></td><td class=\"jobs\">".$shift."</td></tr>"."\n"; } if ($salary !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Salary:</strong></td><td class=\"jobs\">".$salary."</td></tr>"."\n"; } echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Description:</strong></td><td class=\"jobs\">".$desc."</td></tr>"."\n"; if ($quals !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Qualifications:</strong></td><td class=\"jobs\">" .$quals. "</td></tr>"."\n"; } if ($prefd !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Preferred:</strong></td><td class=\"jobs\">" .$prefd. "</td></tr>"."\n"; } if ($howto !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>How To Apply:</strong></td><td class=\"jobs\">".$howto."</td></tr>"."\n"; } if ($url !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Website:</strong></td><td class=\"jobs\"><a href=\"http://".$url."\" target=\"_blank\" class=\"popup\">http://".$url."</a></td></tr>"."\n"; } if ($contName !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Contact Name:</strong></td><td class=\"jobs\">".$contName."</td></tr>"."\n"; } if ($contPhone !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Contact Phone:</strong></td><td class=\"jobs\">".$contPhone."</td></tr>"."\n"; } if ($contEmail !=''){ echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>Contact E-mail:</strong></td><td class=\"jobs\">".$contEmail."</td></tr>"."\n"; } echo "</table>"."\n"; echo "<div>(Added on: " .$added. ")</div>"."\n"; echo "<br/><br/>"."\n";}; }; mysql_close();
Here is the page with the actual output of the script:
http://www.bmet.org/employment.html
One thing in particular that I will be changing at some point is to automatically create the field names (Employer, Title, Salary, etc) by using the actual field names that are in the DB then displaying the other data in a pseudo table that uses the display: table CSS property.
So, any help from you guys will be much appreciated.
|