Re: Include Issues
| From: | Justin Patrin | Date: | Wed, 16 Jun 2004 22:53:01 +0000 |
| Subject: | Re: Include Issues | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188446@lists.php.net to get a copy of this message | ||
Stephen Craton wrote:
I have a script that calls a function called conbox. This function creates the HTML to a content box and you also pass a file to be included into the content area of the box. The function echos out some of the HTML, then does a simple include(), and then echos out the rest of the HTML. I'm trying to do this with another file containing PHP code and HTML together, it's a file that fetches and displays information from a database. The file is fine by itself, but once I include it into the actual content box, it does a die(). I have it set to do that if there's a MySQL error, but it doesn't output any error at all, and the file works by itself. Here is the code that fetches from the database: <?php mysql_select_db($database_default, $default); $query_headlines = "SELECT id, headline, short, datetime FROM snews ORDER BY datetime DESC"; $headlines = mysql_query($query_headlines, $default) or die(mysql_error()); $row_headlines = mysql_fetch_assoc($headlines); $totalRows_headlines = mysql_num_rows($headlines); ?> And here's where it displays: <table width="98%" border="0" cellspacing="0" cellpadding="2" bordercolor="#616161" align="center" style="border-collapse:collapse"> <tr bgcolor="#E0EBF1">You're probably running into a namespace issue here. The global variables that you're trying to use for mysql_select_db aren't in the namespace of the function that's including the file. I would suggest using a better (OOP) system to get around this. Barring that, the best way IMHO is to use $GLOBALS['database_default'], etc. for the vars in the include that are created globally. -- paperCrane <Justin Patrin><td align="left" style="padding:3px 3px 3px 3px;"><ahref="snews.php?id=<?php echo $row_headlines['id']; ?>" class="headline"><?php echo $row_headlines['headline']; ?></a></td> </tr> </table> This is fine, completely fine, by itself (if I include the database credentials of course, but if I leave that include in there, it still won't work). I've already included that file into the file it's being included into anyway so it should work, but it simply isn't. Here's the conbox function with less of the echo: function conbox($title, $contentfile, $content, $width, $height) { echo 'Stuff...'; if($content == '') { if(!@include($contentfile)) { echo 'content unavailable'; } } if($content != '') { echo '<p align="left">'.$content.'</p>'; } echo 'stuff'; } Like I said, all the database credentials and everything is included into the final file, but it simply won't work. Any ideas here? Thanks, Stephen Craton http://www.melchior.us <http://www.melchior.us/>