gmcalp Posted November 18, 2008 Share Posted November 18, 2008 Hi there, I am a new poster but have found several answers to questions that I've had by reading the forums for a while. Anyway, I wrote a script and I was just thinking that it could be optimized or reworked to be a little more efficient with less code. The biggest thing is there are a lot of conditional 'if' statements that I was hoping could be done in a different way. Also, I would like to change the format of the page (which I can do). What I would like to do is to make the row names from the database to become part of the output instead of hard-coding them (Title, Employer, etc) and have the data in those rows output next to them in the next cell (and if there is no data in that row to not even print the row name, just how it works now). Any help would be appreciated. Here's an example of the page as it is now: http://www.bmet.org/employment.html Here's the 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'])); // 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><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(); Thanks again! Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 Here is an example of one way to optimize it. <?php $result = @mysql_query("SELECT loc, fte, shift, salary, quals, prefd, howto, url, contName, contPhone, contEmail, added, jobtitle, empl, id FROM $db_table ORDER BY id DESC"); // I usually define columns I want out but yea, this will ensure the proper order you want them displayed later on. 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)) { // no clue why you define these, I would just access them as needed. $row['added'] = date("m/d/y", strtotime($row['added'])); // convert newline characters to HTML break tag ( <br /> ) $row['desc'] = nl2br($row['desc']); $row['quals'] = nl2br($row['quals']); $row['prefd'] = nl2br($row['prefd']); $row['howto'] = nl2br($row['howto']); echo "<h3>".$row['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\">".$row['jobtitle']."</td></tr>"."\n"; echo "<tr class=\"jobs\" valign=\"top\"><td><strong>Employer:</strong></td><td class=\"jobs\">".$row['empl']."</td></tr>"."\n"; foreach ($row as $key => $val) { if ($key == "added") // edit changed this to key over val like it should be. break; // because that means we past the last line we wanted displayed this way. if ($val != "") echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . replaceTitle($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>"."\n"; } echo "</table>"."\n"; echo "<div>(Added on: " .$row['added']. ")</div>"."\n"; echo "<br/><br/>"."\n"; } } function replaceTitle($title) { $replaceArray = array("loc" => "Location", "fte" => "FTE", "shift" => "Shift", "salary" => "salary"); // add the rest of the titles here. return $replaceArray[$title]; } mysql_close(); ?> Questions let me know. May not be the best, but a way to make it more dynamic with less code. Quote Link to comment Share on other sites More sharing options...
gmcalp Posted November 18, 2008 Author Share Posted November 18, 2008 Thanks for your help. I tried your suggestions but none of the values except for that of the Title and Employer are showing up (see the previously posted URL). I had to change a few of the row names (that's why I defined them, to have shorter names). Here is the code with the updated names... not sure why it's not displaying the things it should: <?php $result = @mysql_query("SELECT id, title, employer, location, fte, shift, salary, description, qualifications, preferred, howtoapply, url, contactname, contactphone, contactemail, added FROM $db_table ORDER BY id DESC"); // I usually define columns I want out but yea, this will ensure the proper order you want them displayed later on. 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)) { // no clue why you define these, I would just access them as needed. $row['added'] = date("m/d/y", strtotime($row['added'])); // convert newline characters to HTML break tag ( <br /> ) $row['description'] = nl2br($row['description']); $row['qualifications'] = nl2br($row['qualifications']); $row['preferred'] = nl2br($row['preferred']); $row['howtoapply'] = nl2br($row['howtoapply']); echo "<h3>".$row['title']."</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\">".$row['title']."</td></tr>"."\n"; echo "<tr class=\"jobs\" valign=\"top\"><td><strong>Employer:</strong></td><td class=\"jobs\">".$row['employer']."</td></tr>"."\n"; foreach ($row as $key => $val) { if ($key == "added") // edit changed this to key over val like it should be. break; // because that means we past the last line we wanted displayed this way. if ($val != "") echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . replaceTableTitle($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>"."\n"; } echo "</table>"."\n"; echo "<div>(Added on: " .$row['added']. ")</div>"."\n"; echo "<br/><br/>"."\n"; } } // add the titles here. function replaceTableTitle($tabletitle) { $replaceArray = array("location" => "Location", "fte" => "FTE", "shift" => "Shift", "salary" => "Salary", "description" => "Description", "qualifications" => "Qualifications", "preferred" => "Preferred", "howtoapply" => "How To Apply", "url" => "URL", "contactname" => "Contact Name", "contactphone" => "Contact Phone", "contactemail" => "Contact Email"); return $replaceArray[$tabletitle]; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 Thanks for your help. I tried your suggestions but none of the values except for that of the Title and Employer are showing up (see the previously posted URL). I had to change a few of the row names (that's why I defined them, to have shorter names). Here is the code with the updated names... not sure why it's not displaying the things it should: <?php $result = @mysql_query("SELECT id, title, employer, location, fte, shift, salary, description, qualifications, preferred, howtoapply, url, contactname, contactphone, contactemail, added FROM $db_table ORDER BY id DESC"); // I usually define columns I want out but yea, this will ensure the proper order you want them displayed later on. 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)) { // no clue why you define these, I would just access them as needed. $row['added'] = date("m/d/y", strtotime($row['added'])); // convert newline characters to HTML break tag ( <br /> ) $row['description'] = nl2br($row['description']); $row['qualifications'] = nl2br($row['qualifications']); $row['preferred'] = nl2br($row['preferred']); $row['howtoapply'] = nl2br($row['howtoapply']); echo "<h3>".$row['title']."</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\">".$row['title']."</td></tr>"."\n"; echo "<tr class=\"jobs\" valign=\"top\"><td><strong>Employer:</strong></td><td class=\"jobs\">".$row['employer']."</td></tr>"."\n"; foreach ($row as $key => $val) { if ($key == "added") // edit changed this to key over val like it should be. break; // because that means we past the last line we wanted displayed this way. if ($val != "") echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . replaceTableTitle($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>"."\n"; } echo "</table>"."\n"; echo "<div>(Added on: " .$row['added']. ")</div>"."\n"; echo "<br/><br/>"."\n"; } } // add the titles here. function replaceTableTitle($tabletitle) { $replaceArray = array("location" => "Location", "fte" => "FTE", "shift" => "Shift", "salary" => "Salary", "description" => "Description", "qualifications" => "Qualifications", "preferred" => "Preferred", "howtoapply" => "How To Apply", "url" => "URL", "contactname" => "Contact Name", "contactphone" => "Contact Phone", "contactemail" => "Contact Email"); return $replaceArray[$tabletitle]; } mysql_close(); ?> Ah, now that I know the old variables was just to shorten, this will work instead: <?php // the order above has to be as such so when we get to the foreach it displays properly. $result = @mysql_query("SELECT location, fte, shift, salary, description, qualifications, preferred, howtoapply, url, contactname, contactphone, contactemail, added, id, title, employer FROM $db_table ORDER BY id DESC"); // I usually define columns I want out but yea, this will ensure the proper order you want them displayed later on. 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)) { // no clue why you define these, I would just access them as needed. $row['added'] = date("m/d/y", strtotime($row['added'])); // convert newline characters to HTML break tag ( <br /> ) $row['description'] = nl2br($row['description']); $row['qualifications'] = nl2br($row['qualifications']); $row['preferred'] = nl2br($row['preferred']); $row['howtoapply'] = nl2br($row['howtoapply']); echo "<h3>".$row['title']."</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\">".$row['title']."</td></tr>\n"; echo "<tr class=\"jobs\" valign=\"top\"><td><strong>Employer:</strong></td><td class=\"jobs\">".$row['employer']."</td></tr>\n"; foreach ($row as $key => $val) { if ($key == "added") break; // because that means we past the last line we wanted displayed this way. if ($val != "") echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . ucfirst($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>\n"; } echo "</table>\n"; echo "<div>(Added on: " .$row['added']. ")</div>\n"; echo "<br/><br/>\n"; } } mysql_close(); ?> The above should work, remember that the initial select is setup in a way so that the foreach loops through it right and displays only the columns it should at the time, once it hit's added it stops so it does not display the last few column. If that still does not work I would do this for a test: <?php // the order above has to be as such so when we get to the foreach it displays properly. $result = @mysql_query("SELECT location, fte, shift, salary, description, qualifications, preferred, howtoapply, url, contactname, contactphone, contactemail, added, id, title, employer FROM $db_table ORDER BY id DESC"); // I usually define columns I want out but yea, this will ensure the proper order you want them displayed later on. 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)) { // no clue why you define these, I would just access them as needed. $row['added'] = date("m/d/y", strtotime($row['added'])); // convert newline characters to HTML break tag ( <br /> ) $row['description'] = nl2br($row['description']); $row['qualifications'] = nl2br($row['qualifications']); $row['preferred'] = nl2br($row['preferred']); $row['howtoapply'] = nl2br($row['howtoapply']); echo '<pre>'; // remove after test print_r($row); // remove after test die(); // remove after test echo "<h3>".$row['title']."</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\">".$row['title']."</td></tr>\n"; echo "<tr class=\"jobs\" valign=\"top\"><td><strong>Employer:</strong></td><td class=\"jobs\">".$row['employer']."</td></tr>\n"; foreach ($row as $key => $val) { if ($key == "added") break; // because that means we past the last line we wanted displayed this way. if ($val != "") echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . ucfirst($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>\n"; } echo "</table>\n"; echo "<div>(Added on: " .$row['added']. ")</div>\n"; echo "<br/><br/>\n"; } } mysql_close(); ?> And see what gets printed out. Quote Link to comment Share on other sites More sharing options...
gmcalp Posted November 18, 2008 Author Share Posted November 18, 2008 Here's the output of that test (the second go didn't work): Array ( [0] => Seattle, WA [location] => Seattle, WA [1] => Full Time [fte] => Full Time [2] => Day [shift] => Day [3] => $3438 - $4924 Per Month [salary] => $3438 - $4924 Per Month [4] => As the region's only Level I Trauma center, Harborview Medical Center (HMC) is well known for innovations and excellence in trauma care and its centers of emphasis: Trauma, Burn, Neurosciences, AIDS/STD CARER, and mentally-and medically- vulnerable populations. In addition to the centers of emphasis, HMC serves a mission population for King County. Harborview employees are committed to the vital role the institution plays in the immediate community, as well as the entire Northwest region. HMC is owned by King County and managed by the University of Washington (UW) and serves as a training site for UW's School of Medicine. The UW is proud to be one of the nation's premier educational and research institutions. Our people are the most important asset in our pursuit of achieving excellence in education, research, and community service. Our staff not only enjoys outstanding benefits and professional growth opportunities, but also an environment noted for diversity, community involvement, intellectual excitement, artistic pursuits, and natural beauty. Harborview Medical Center received the prestigious 2007 Foster G. McGaw Prize for Excellence in Community Service, one of the most esteemed honors of excellence in community service in healthcare. Our CLINICAL ENGINEERING department has an outstanding opportunity for a BIOMEDICAL TECHNICIAN 1. This position performs entry-level biomedical electronics work to troubleshoot, repair, maintain, install, test and calibrate a variety of analog and/or digital biomedical electronic instruments, apparatus, and equipment used in a healthcare facility. This will involve maintaining, troubleshooting, and repairing mechanical electromechanical and electronic equipment and apparatus used in Patient Care; calibrating and testing mechanical, electromechanical and electronic equipment or apparatus used in patient care, and constructing simple electrical circuits or assemblies designed by others for use in patient care. Additionally, the person in this role will prepare reports, documentation and data entry in accordance with hospital procedures, and establish and maintain good customer relationships. [description] => As the region's only Level I Trauma center, Harborview Medical Center (HMC) is well known for innovations and excellence in trauma care and its centers of emphasis: Trauma, Burn, Neurosciences, AIDS/STD CARER, and mentally-and medically- vulnerable populations. In addition to the centers of emphasis, HMC serves a mission population for King County. Harborview employees are committed to the vital role the institution plays in the immediate community, as well as the entire Northwest region. HMC is owned by King County and managed by the University of Washington (UW) and serves as a training site for UW's School of Medicine. The UW is proud to be one of the nation's premier educational and research institutions. Our people are the most important asset in our pursuit of achieving excellence in education, research, and community service. Our staff not only enjoys outstanding benefits and professional growth opportunities, but also an environment noted for diversity, community involvement, intellectual excitement, artistic pursuits, and natural beauty. Harborview Medical Center received the prestigious 2007 Foster G. McGaw Prize for Excellence in Community Service, one of the most esteemed honors of excellence in community service in healthcare. Our CLINICAL ENGINEERING department has an outstanding opportunity for a BIOMEDICAL TECHNICIAN 1. This position performs entry-level biomedical electronics work to troubleshoot, repair, maintain, install, test and calibrate a variety of analog and/or digital biomedical electronic instruments, apparatus, and equipment used in a healthcare facility. This will involve maintaining, troubleshooting, and repairing mechanical electromechanical and electronic equipment and apparatus used in Patient Care; calibrating and testing mechanical, electromechanical and electronic equipment or apparatus used in patient care, and constructing simple electrical circuits or assemblies designed by others for use in patient care. Additionally, the person in this role will prepare reports, documentation and data entry in accordance with hospital procedures, and establish and maintain good customer relationships. [5] => Competitive candidates will: * Have knowledge of calibrating/testing equipment, such as oscilloscopes, digital millimeters, function generators, calibrators, electro surgery and safety analyzers, defibrillator testers, and FR watt meters. * Have the ability to perform preventative maintenance and/or electrical safety inspections on basic patient care and clinical laboratory equipment: Test, adjust, and calibrate to federal, state, and local electrical and fire safety standards. * Have the ability to construct simple electrical circuits or assemblies designed by others for use in patient care. * Skilled in connecting boards to power supplies and fabricating enclosures. * Have the ability to connect boards to power supplies and fabricating enclosures. This position provides opportunities to work in a fast-paced environment, and work with a friendly group of people. As an employee you will enjoy generous benefits and work/life programs. As an employee you will enjoy generous benefits and work/life programs. For a complete description of our benefits for this position, please view this page. Requirements: An Associate's Degree in Biomedical Technology OR equivalent education/experience OR Certification by the Association for the Advancement of Medical Instrumentation (AAMI) as a candidate. Condition of Employment: * Monday through Friday work schedule- 8:30 a.m. - 5:00 p.m. * May have some on-call duties. [qualifications] => Competitive candidates will: * Have knowledge of calibrating/testing equipment, such as oscilloscopes, digital millimeters, function generators, calibrators, electro surgery and safety analyzers, defibrillator testers, and FR watt meters. * Have the ability to perform preventative maintenance and/or electrical safety inspections on basic patient care and clinical laboratory equipment: Test, adjust, and calibrate to federal, state, and local electrical and fire safety standards. * Have the ability to construct simple electrical circuits or assemblies designed by others for use in patient care. * Skilled in connecting boards to power supplies and fabricating enclosures. * Have the ability to connect boards to power supplies and fabricating enclosures. This position provides opportunities to work in a fast-paced environment, and work with a friendly group of people. As an employee you will enjoy generous benefits and work/life programs. As an employee you will enjoy generous benefits and work/life programs. For a complete description of our benefits for this position, please view this page. Requirements: An Associate's Degree in Biomedical Technology OR equivalent education/experience OR Certification by the Association for the Advancement of Medical Instrumentation (AAMI) as a candidate. Condition of Employment: * Monday through Friday work schedule- 8:30 a.m. - 5:00 p.m. * May have some on-call duties. [6] => * Very high mechanical aptitude. * Computer and networking skills * Maintenance skills in electronics, mechanical or electromechanical device repair. * Ability to read color codes on wiring and electrical components. * Ability to comprehend and follow both written and oral instructions. * Ability to establish and maintain working relationships with co-workers, clinical and medical staff, and the general public. * An elementary knowledge of e-mail, database management, spreadsheet, and word processor applications. * Ability to work nights, weekends, and holidays if necessary. * Ability to function in a sterile environment if necessary. * Ability to keep neat and accurate records. * Must be willing to be multi-task trained. [preferred] => * Very high mechanical aptitude. * Computer and networking skills * Maintenance skills in electronics, mechanical or electromechanical device repair. * Ability to read color codes on wiring and electrical components. * Ability to comprehend and follow both written and oral instructions. * Ability to establish and maintain working relationships with co-workers, clinical and medical staff, and the general public. * An elementary knowledge of e-mail, database management, spreadsheet, and word processor applications. * Ability to work nights, weekends, and holidays if necessary. * Ability to function in a sterile environment if necessary. * Ability to keep neat and accurate records. * Must be willing to be multi-task trained. [7] => Apply via the following URL: https://uwhires.admin.washington.edu/eng/candidates/default.cfm?szCategory=candidatepaste&szOrderID=48979 [howtoapply] => Apply via the following URL: https://uwhires.admin.washington.edu/eng/candidates/default.cfm?szCategory=candidatepaste&szOrderID=48979 [8] => [url] => [9] => [contactname] => [10] => [contactphone] => [11] => [contactemail] => [12] => 2008-11-12 [added] => 11/12/08 [13] => 46 [id] => 46 [14] => BIOMEDICAL ELECTRONICS TECHNICIAN 1 [title] => BIOMEDICAL ELECTRONICS TECHNICIAN 1 [15] => Harborview Medical Center [employer] => Harborview Medical Center ) Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 Ah I forgot you were using the fetch_array. Only use this if you really want both set (non-assoc and assoc) results other wise use fetch_assoc. <?php // the order above has to be as such so when we get to the foreach it displays properly. $result = @mysql_query("SELECT location, fte, shift, salary, description, qualifications, preferred, howtoapply, url, contactname, contactphone, contactemail, added, id, title, employer FROM $db_table ORDER BY id DESC"); // I usually define columns I want out but yea, this will ensure the proper order you want them displayed later on. 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_assoc($result)) { // changed to fetch_assoc to only grab one set of data. // no clue why you define these, I would just access them as needed. $row['added'] = date("m/d/y", strtotime($row['added'])); // convert newline characters to HTML break tag ( <br /> ) $row['description'] = nl2br($row['description']); $row['qualifications'] = nl2br($row['qualifications']); $row['preferred'] = nl2br($row['preferred']); $row['howtoapply'] = nl2br($row['howtoapply']); echo "<h3>".$row['title']."</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\">".$row['title']."</td></tr>\n"; echo "<tr class=\"jobs\" valign=\"top\"><td><strong>Employer:</strong></td><td class=\"jobs\">".$row['employer']."</td></tr>\n"; foreach ($row as $key => $val) { if ($key == "added") break; // because that means we past the last line we wanted displayed this way. if ($val != "") echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . ucfirst($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>\n"; } echo "</table>\n"; echo "<div>(Added on: " .$row['added']. ")</div>\n"; echo "<br/><br/>\n"; } } mysql_close(); ?> Give that a try and see if that works. Quote Link to comment Share on other sites More sharing options...
gmcalp Posted November 18, 2008 Author Share Posted November 18, 2008 Excellent... we're getting there. Now, is there a way to format the last few Titles (Howtoapply, Url, Contactname, Contactphone, Contactemail) so that they are like this: URL, How To Apply, Contact Name, Contact Phone, Contact Email; without having to rename the rows in my DB? Quote Link to comment Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 You could take the concept of the replaceTableTitle and do it that way. function replaceTableTitle($title) { switch (strtolower($title)) { case 'howtoapply': return "How To Apply"; break; // etc } // if we get here just upercase the first word return ucfirst($title); } Then just replace this part of the code: echo "<tr class=\"jobs\" valign=\"top\"><td class=\"jobs\"><strong>" . replaceTableTitle($key) . ":</strong></td><td class=\"jobs\">".$val."</td></tr>\n"; Quote Link to comment Share on other sites More sharing options...
gmcalp Posted November 18, 2008 Author Share Posted November 18, 2008 So, for subsequent changes, would it be like this? function replaceTableTitle($title) { switch (strtolower($title)) { case 'howtoapply': return "How To Apply"; case 'url': return "URL"; //ETC break; // etc } OR like this: function replaceTableTitle($title) { switch (strtolower($title)) { case 'howtoapply': return "How To Apply"; break; case 'url': return "URL"; break; // etc Quote Link to comment Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 Either or works. With the return in there that breaks the switch. Quote Link to comment Share on other sites More sharing options...
gmcalp Posted November 19, 2008 Author Share Posted November 19, 2008 I went ahead and used the first one and it works fabulously! Thank you sir for all your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.