jaxdevil Posted July 26, 2008 Share Posted July 26, 2008 I have a code I use to display items from my database and paginate them. The html portion is inside a container that starts with <<<HTML and ends with HTML; , I do not know what that is. Inside the code I am trying to run a small php if statement and it won't work inside of it. What kind of container is this code and how can I run php inside of it? Here is the code I am trying to run inside of it and below is the entire page, you will see where the code is at and the <<<HTML container, whatever that is. BTW all the code calls inside of it are inside curly brackets, if that helps to figure out what kind of container it is. <? if ( $act == "yes") { ?> <img src="images/active.jpg" border="0"> <? } if ( $act == "no") { ?> <img src="images/inactive.jpg" border="0"> <? } else { ?> <img src="images/active.jpg" border="0"> <? } ?> <?php // $Id: desktop.php,v 0.1 2007/07/25 16:54:40 xsds Exp $ // include common files require_once("includes/common.inc.php"); validateAdmin(); $msg = get_message(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php print $config['siteAdminTitle']?></title> <link href="css/css.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center" valign="top" bgcolor="#FFFFFF" class="white-bg"><?php include("includes/header.inc.php"); ?></td> </tr> <tr> <td align="center" valign="top" bgcolor="#FFFFFF" class="white-bg paddingright10"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td height="25" colspan=4> </td></tr> <tr> <?php require_once("includes/leftpanel.inc.php");?> <!-- BODY START--> <td width="100%" align="center" valign="top" bgcolor="#EEEEEE" class="border-rt"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="middle" class="header_bg "><img alt="Admin Panel" src="images/heading_icon.gif" width="16" height="16" hspace="5" align="left" /><span class="h1">Language Modules Admin </span></td> </tr> <tr> <td> </td> </tr> <tr> <td align="center" valign="top"><table width="94%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"> <?php require( $_SERVER['DOCUMENT_ROOT']."/configs/connection.php"); ?> <?php // Select total results for pagination $result = mysql_query("SELECT count(*) FROM langs") or die(mysql_error()); $num_records = mysql_result($result,0,0); // Set maximum number of rows and columns $max_num_rows = 25; $max_num_columns = 1; $per_page = $max_num_columns * $max_num_rows; // Work out how many pages there are $total_pages = ceil($num_records / $per_page); // Get the current page number if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; // Work out the limit offset $start = ($page - 1) * $per_page; // Select the results we want including limit and offset $result = mysql_query("SELECT `lang` FROM langs LIMIT $start, $per_page") or die(mysql_error()); $lang = mysql_query("SELECT `lang` FROM langs LIMIT $start, $per_page") or die(mysql_error()); $name = mysql_query("SELECT `name` FROM langs LIMIT $start, $per_page") or die(mysql_error()); $act = mysql_query("SELECT `act` FROM langs LIMIT $start, $per_page") or die(mysql_error()); $custom = mysql_query("SELECT `custom` FROM langs LIMIT $start, $per_page") or die(mysql_error()); $num_columns = ceil(mysql_num_rows($result)/$max_num_rows); $num_rows = ceil(mysql_num_rows($result)/$num_columns); // Echo the results ?> <table width="550" border="1" bordercolor="black" cellpadding="0" cellspacing="0" style="border-left-width:0px; border-top-width: 1px; border-bottom-width: 0px; border-right-width: 0px;"> <tr width="550"> <td width="50"> <b><font face="Tahoma,Verdana,Arial" size="0.90em">Status</font></b> </td> <td width="270"> <b><font face="Tahoma,Verdana,Arial" size="0.90em">Language</font></b> </td> <td width="40"> <b><font face="Tahoma,Verdana,Arial" size="0.90em">Flag</font></b> </td> <td width="150"> <b><font face="Tahoma,Verdana,Arial" size="0.90em">Set Option</font></b> </td> <td width="40"> <b><font face="Tahoma,Verdana,Arial" size="0.90em">Edit Module</font></b> </td> </tr> <? for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr width=\"550\" height=\"5\">\n"; for ($c = 0; $c < $max_num_columns; $c++){ // 1 $x = $r * $max_num_columns + $c; if ($x < mysql_num_rows($result)){ $lang_r = mysql_result($lang, $x, 0); $name_r = mysql_result($name, $x, 0); $act_r = mysql_result($act, $x, 0); $custom_r = mysql_result($custom, $x, 0); $y = <<<HTML <td width="50" valign="middle"> <center> <? if ( $act == "yes") { ?> <img src="images/active.jpg" border="0"> <? } if ( $act == "no") { ?> <img src="images/inactive.jpg" border="0"> <? } else { ?> <img src="images/active.jpg" border="0"> <? } ?> </center> </td> <td width="270" align="center" valign="middle"> {$name_r} </td> <td width="40" valign="middle"> <center> <img src="/flags/{$lang_r}.gif" border="0"> </center> </td> <form action="" method="post"> <td width="150" valign="middle"> <center> <SELECT NAME="lang_opt" style="width:225px; border:0px solid; height:17px; padding:0px 3px; position:relative;" onchange='this.form.submit()'> <OPTION VALUE="NONE">-----Select Action----- <font style="font-size: 0.7em;" face="Tahoma"> <OPTION VALUE="Active">Active <OPTION VALUE="Inactive">Inactive <OPTION VALUE="Custom">Custom </font> </SELECT> </center> </td> </form> <td width="40"> <center> <a href="lang_mod.php?lang={$lang_r}"><img src="images/edit.gif" border="0"></a> </center> </td> HTML; } else { $y = ''; } echo "$y"; } echo "</tr>\n"; } // Echo page numbers echo "</table></center><center>\n"; echo "<table width=480 cellspacing=0 cellpadding=0 border=0><tr><td><font face=\"Tahoma,Verdana,Arial\" size=0.50em><center>Go to: "; // Echo the results for ($i=1;$i <= $total_pages;$i++) { if ($i == $page) echo " $i "; else echo " <a href=\"?action=List&page=$i\">$i</a> ";} ?> </font></center></td></tr></table> </div> </font> </div> <br> </td> </tr> </table></td> </tr> <?php if(check_not_null($msg)) { ?> <tr> <td align="center"><?php echo $msg; ?></td> </tr> <?php } ?> <tr> <td> </td> </tr> </table></td> </tr> </table> </td> </tr> <tr> <td align="center" valign="top" class="white-bg"> </td> </tr> <tr> <td align="center" valign="top" bgcolor="#94A1B0"><?php include("includes/footer.inc.php"); ?></td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 It's called a heredoc. Google it. You can't run PHP inside of it, just like you can't run PHP inside of any other string. Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted July 26, 2008 Author Share Posted July 26, 2008 Can I make a function outside of it and call it from within inside the curly brackets? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 27, 2008 Share Posted July 27, 2008 try it. Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted July 27, 2008 Author Share Posted July 27, 2008 I tried, its not working. I redid the code to be an echo instead of the heredoc thing, and I am trying to call the code as a function, but its not working. I am copying the function I made below and the way I am trying to call it, its not working so maybe you can see what I am doing wrong? <?php function displayIcon($icon_code) { if ( $icon_code == "yes") { ?> <img src="images/active.gif" border="0"> <? } if ( $icon_code == "no") { ?> <img src="images/inactive.gif" border="0"> <? } } $icon_r = displayIcon(yes); echo "{$icon_r}"; ?> Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted July 27, 2008 Author Share Posted July 27, 2008 I figured it out. 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.