Ok, no offense to redheads or stepchildren…needed a catchy title. I am new to PHP, have code that “works”, but it sure looks inefficient to me. anyone know of a better way to handle the repetitive IF Else statements?
Thanks in advance.
Here’s the code.
<?php
// Make a MySQL Connection
// Get all the data from the “members” table
$result = mysql_query(“SELECT * FROM members ORDER BY Utility ASC,Person ASC”)
or die(mysql_error());
echo “<table border=’1′>”;
echo “<tr> <th>First Name</th> <th>Last Name</th> <th>Title</th> <th>Email</th> <th>Company</th></tr>”;
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
if ($row[‘Utility’]==”1″) {
echo “Utility Name 1”;
} else {
if ($row[‘Utility’]==”2″) {
echo “Utility Name 2”;
} else {
if ($row[‘Utility’]==”3″) {
echo “Utility Name 3”;
} else {
if ($row[‘Utility’]==”4″) {
echo “Utility Name 4”;
} else {
if ($row[‘Utility’]==”5″) {
echo “Utility Name 5”;
} else {
if ($row[‘Utility’]==”6″) {
echo “Utility Name 6”;
} else {
if ($row[‘Utility’]==”7″) {
echo “Utility Name 7”;
} else {
if ($row[‘Utility’]==”8″) {
echo “Utility Name 8”;
} else {
if ($row[‘Utility’]==”9″) {
echo “Utility Name 9”;
} else {
if ($row[‘Utility’]==”10″) {
echo “Utility Name 10”;
} else {
if ($row[‘Utility’]==”11″) {
echo “Utility Name 11”;
} else {
if ($row[‘Utility’]==”12″) {
echo “Utility Name 12”;
} else {
if ($row[‘Utility’]==”13″) {
echo “Utility Name 13”;
} else {
if ($row[‘Utility’]==”14″) {
echo “Utility Name 14”;
} else {
if ($row[‘Utility’]==”15″) {
echo “Utility Name 15”;
} else {
if ($row[‘Utility’]==”16″) {
echo “Utility Name 16”;
} else {
if ($row[‘Utility’]==”17″) {
echo “Utility Name 17”;
} else {
if ($row[‘Utility’]==”18″) {
echo “Utility Name 18”;
} else {
if ($row[‘Utility’]==”19″) {
echo “Utility Name 19”;
} else {
if ($row[‘Utility’]==”20″) {
echo “Utility Name 20”;
} else {
if ($row[‘Utility’]==”21″) {
echo “Utility Name 21”;
} else {
if ($row[‘Utility’]==”22″) {
echo “Utility Name 22”;
} else {
if ($row[‘Utility’]==”23″) {
echo “Utility Name 23”;
} else {
if ($row[‘Utility’]==”24″) {
echo “Utility Name 24”;
} else {
if ($row[‘Utility’]==”25″) {
echo “Utility Name 25”;
} else {
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
echo “<br>”;
if ($row[‘JobCategory’]==”presceo”) {
echo “President and CEO”;
} else {
if ($row[‘JobCategory’]==”coo”) {
echo “Chief Operating Officer”;
} else {
if ($row[‘JobCategory’]==”cfo”) {
echo “Top Financial Executive”;
} else {
if ($row[‘JobCategory’]==”legal”) {
echo “Top Legal Executive”;
} else {
if ($row[‘JobCategory’]==”nuclear”) {
echo “Top Nuclear Executive”;
} else {
if ($row[‘JobCategory’]==”generation”) {
echo “Top Power Generation Executive–non-nuclear”;
} else {
if ($row[‘JobCategory’]==”distribution”) {
echo “Top Distribution Executive”;
} else {
if ($row[‘JobCategory’]==”transmission”) {
echo “Top Transmission Systems Executive”;
} else {
if ($row[‘JobCategory’]==”energymarketing”) {
echo “Top Energy Marketing Executive”;
} else {
if ($row[‘JobCategory’]==”strategicplanning”) {
echo “Top Strategic Planning Executive”;
} else {
if ($row[‘JobCategory’]==”communications”) {
echo “Top Communications Executive”;
} else {
if ($row[‘JobCategory’]==”custservice”) {
echo “Top Customer Service Executive”;
} else {
if ($row[‘JobCategory’]==”cio”) {
echo “Information Technology and Services–CIO”;
} else {
if ($row[‘JobCategory’]==”financial”) {
echo “Finance Accounting and Information Services”;
} else {
if ($row[‘JobCategory’]==”hr”) {
echo “Human Resources”;
} else {
if ($row[‘JobCategory’]==”gr”) {
echo “Government Relations”;
} else {
if ($row[‘JobCategory’]==”safety”) {
echo “Safety”;
} else {
if ($row[‘JobCategory’]==”gasutility”) {
echo “Gas Utility Executive”;
} else {
if ($row[‘JobCategory’]==”water”) {
echo “Water Executive”;
} else {
if ($row[‘JobCategory’]==”wholesale”) {
echo “Wholesale Executive”;
} else {
if ($row[‘JobCategory’]==”retailsales”) {
echo “Retail Sales Executive”;
} else {
if ($row[‘JobCategory’]==”corpplanning”) {
echo “Corporate Planning Executive”;
} else {
if ($row[‘JobCategory’]==”utilitiesservices”) {
echo “Utilities Services Executive”;
} else {
if ($row[‘JobCategory’]==”marketing”) {
echo “Marketing Executive”;
} else {
if ($row[‘JobCategory’]==”electric”) {
echo “Electric Department Executive”;
} else {
if ($row[‘JobCategory’]==”environmental”) {
echo “Top Environmental Affairs Executive”;
} else {
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
echo “<br>”;
echo $row[‘FirstName’];
echo ” “;
echo $row[‘LastName’];
echo “, “;
echo $row[‘Title’];
echo “<br>”;
echo “work: “;
echo $row[‘WorkPhone’];
echo “<br>”;
echo “cell: “;
echo $row[‘CellPhone’];
echo “<br>”;
echo “fax: “;
echo $row[‘Fax’];
echo “<br>”;
echo “email: “;
echo ‘<a href=”mailto:’ . $row[‘Email’] . ‘”>’ . $row[‘Email’] . ‘</a>’;
echo “<br><br><hr>”;
}
?>