I did a lot of homework on IF statements recently. Below are copies of some of the scripts I'm using now.
This first example draws on a database filled with the names of the world's continents, oceans, nations and states, each given an ID in a field named IDArea. Each page on my site has an echo statement - $mycode - which is matched to a value in IDArea. I want most of the higher ranking pages to display an index of the nations or states they include. So the script below says that the pages Earth ($mycode = ear), North America ($mycode = na), etc. will include a file named include/index/$mycode.php. Thus, the Earth page will include include/index/ear.php. You can see this index in the right column of the page at www.geozoo.org/world/ <?php switch ( $data_details['IDArea'] ) { case 'ear': case 'na': case 'cam': case 'usa': case 'can': case 'mex': include($_SERVER['DOCUMENT_ROOT'] . '/include/index/' . $mycode . '.php'); break; default: include($_SERVER['DOCUMENT_ROOT'] . '/include/ads.php'); break; } ?> But I want all the pages that don't feature indexes to display affiliate ads, like those on my France page at http://www.geozoo.org/world/eur/fra/. * * * * * * * * * * The followingn script says that IF there's any data for a particular page ($mycode, like usa) in a field named GZArticle, then everything between the first line (the IF statement) and the last line (ENDIF) will be displayed: <? if($r['GZArticle'] !=''): ?> <span id="navintro" class="menuDiv"> <span id="navintro2" class="menuDivHeader" onclick="P7_swapClass(1,'mnintro','showIt','hideIt','div');P7_swapClass(1,'but1','menuButMinus','menuButPlus','img')">Introduction</span></span> <? endif; ?> * * * * * * * * * * I can't even remember exactly how the following script works, at least not at this late hour. But it displays various trivia only if there are trivia items in the relevant database table cells: <table id="tabtrivia"> <tr> <th>Biggest Native Land Mammal*</th> <th style='background: #fcf;'>Animal Trivia</th> </tr> <? while ($row = mysql_fetch_array ($res)) { ?> <tr class="<? echo $class; ?>"> <td style="width:50%"><? echo $row['Biggest']; ?> <? if($row['Latin'] != '' ) { ?> (<em><? echo $row['Latin']; ?></em>) ~ <? echo $row['Size']; ?> lb. <? } ?> </td> <td style='padding: 0px 10px 10px; background: #fcf; text-align: left'> <? echo $row['Trivia']; ?> </td> </tr> <? } ?> </table> <? } ?> * * * * * * * * * * The following script is from my head section. It uses a combination of $mycode (e.g. usa) and $mykind (e.g. nation) values to determine what style sheets are displayed on various pages. <?php switch ($mykind) { case 'pla': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" />'); break; case 'about': echo ('<link href="/css/about.css" rel="stylesheet" type="text/css" />'); break; case 'ref': echo ('<link href="/css/ref.css" rel="stylesheet" type="text/css" />'); break; case 'topic': echo ('<link href="/css/topics.css" rel="stylesheet" type="text/css" />'); break; } ?> <?php switch ($mycode) { case 'ear': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" />'); break; case 'na': case 'sa': case 'cam': case 'eur': case 'mes': case 'afr': case 'aus': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/a1/css/' . $mycode . '.css" rel="stylesheet" type="text/css" />'); break; case 'anx': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/css/ant.css" rel="stylesheet" type="text/css" />'); break; case 'oce': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/css/' . $mycode . '.css" rel="stylesheet" type="text/css" />'); break; case 'pac': case 'atl': case 'ino': case 'arc': case 'sou': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/css/oce.css" rel="stylesheet" type="text/css" /> <link href="/css/oce/' . $mycode . '.css" rel="stylesheet" type="text/css" />'); break; } ?> <?php switch ( $data_details['IDParent'] ) { case 'na': case 'sa': case 'eur': case 'mes': case 'afr': case 'aux': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/css/' . $data_details['IDParent'] . '.css" rel="stylesheet" type="text/css" /> <link href="/css/' . $data_details['IDParent'] . '/' . $data_details['IDParentReg'] . '.css" rel="stylesheet" type="text/css" />'); break; case 'pac': case 'atl': case 'ino': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/css/oce.css" rel="stylesheet" type="text/css" /> <link href="/css/' . $data_details['IDParent'] . '.css" rel="stylesheet" type="text/css" /> <link href="/css/oce/' . $data_details['IDParentReg'] . '.css" rel="stylesheet" type="text/css" />'); break; case 'usa': case 'can': case 'mex': echo ('<link href="/css/world.css" rel="stylesheet" type="text/css" /> <link href="/css/na.css" rel="stylesheet" type="text/css" /> <link href="/css/na/' . $data_details['IDParentReg'] . '.css" rel="stylesheet" type="text/css" />'); break; /* default: print '<a href="/' . str_replace(" ", "_", strtolower($r['NameParent'])) . '/">' . $data_details['NameParent'] . '</a> >'; break; */ } ?> * * * * * * * * * * Towards the end of the script below, you'll see an IF satement that says IF there's a nickname in a cell named NNPx, then echo (display) that nickname. Otherwise, include a page named suggest/nickname.php. (Most of the pages on all my sites are designed to display a title, subtitle (or nickname) and quote. If no nickname or quote is available, they're replaced with a message inviting people to submit ideas.) <?php // $foo = array("us-", "ca-"); // $mycode_2Char = str_replace($foo, "", $mycode_2Char); $result = mysql_query('select count(*) from gzstates'); if (($result) && (mysql_result ($result , 0) > 0)) { } else { die('Invalid query: ' . mysql_error()); } { $data_details[IDParent] = substr("$data_details[IDParent]", 0, 2); // returns "1st 2 characters, turning usa into us" $res = mysql_query ("SELECT * FROM gzstates where IDArea = '$data_details[IDParent]-$mycode_2Char'") or die (mysql_error()); //<!-- BeginDynamicTable --> while ($row = mysql_fetch_array ($res)) { if ($row['NNPx']) echo ($row['NNPx']); else include($_SERVER['DOCUMENT_ROOT']."/includes/suggest/nickname.php"); // echo ''. $row['NNPx'] .''; } } ?> * * * * * * * * * * In the middle of the script I pasted below, you'll find this code: { if(empty($row['YearEnded'])) { $class='hilite'; } else { $class= ''; } It says if there's no data in a database table cell named YearEnded (the year a governor's term ended), give that a row a class named hilite. Thus, <tr> becomes <tr class="hilite"> Otherwise, leave it <tr class=''>, or something like that. Thus, rows representing CURRENT governors (whose terms haven't ended are hilited yellow. If I remember correctly, the following script inserts a link closing tag - </a> - IF a link is included in a cell named LinkPA. if($row['LinkPA'] != '') { print("</a>"); } Here's the entire script: <?php $result = mysql_query('select count(*) from pxgovernors'); if (($result) && (mysql_result ($result , 0) > 0)) { } else { die('Invalid query: ' . mysql_error()); } { $res = mysql_query ("SELECT * FROM pxgovernors where IDArea = 'us-$mycode'") or die (mysql_error()); echo '<table id="tabgov"> <tr><th colspan="3">Governors</th></tr> <tr><th>Name</th><th class="cfff">Party</th><th>Term(s)</th></tr>'; //<!-- BeginDynamicTable --> while ($row = mysql_fetch_array ($res)) { if(empty($row['YearEnded'])) { $class='hilite'; } else { $class= ''; } echo '<tr class="'.$class.'"><td class="name">'. $row['LinkSenWiki'] , $row['NameFirst'] . ' ' . $row['NameLast'] .''; if($row['LinkPA'] != '') { print("</a>"); } echo '</td> <td class="cfff">'. $row['Party'] .'</td> <td>'. $row['YearBegan'] . '-' . $row['YearEnded'] .''; echo '</td> </tr>'."\n"; } } echo '</table>'; ?> * * * * * * * * * * That isn't a clear answer to your question, but maybe it will give you some ideas. I'm still getting the hang of it myself. --- Sue Cram <[EMAIL PROTECTED]> wrote: > Thanks to the people who helped me with my IF > statement question last night. Now I need to carry > it one step further to a compound 'IF' statement. > Again, can't find much information in the manuals -- > > Several people sent me "IF (Adopted=1, 'Y', 'N') AS > Adopted FROM Animal" and it works great. Now I want > my report to show the English Language meaning for a > field ('Location' in a table called 'Animal') that > contains numeric values. In other languages it > would be something like this (a compound if > statement): > > IF Location=1 > MOVE 'Downstairs Cat Room' to Location > ELSE IF Location=2 > MOVE 'Kitten Room' to Location > ELSE IF Location=3 > MOVE 'Quarantine ' to Location > ELSE MOVE 'Unknown' to Location > END IF > > In other words, I want to test for the comparison > being true, and if it isn't true I want to test it > again for another value... I couldn't find any > information about this construct in the manuals or > past list messages. I also tried using the 'CASE .. > WHEN .. THEN .. END' but couldn't figure out the > syntax errors I was getting. > > Thanks again for your help and support- > Sue > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]