Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include file problem

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have a major problem and i can't figure out what is causing it. Hope you can help me:

What it does is it includes the pages into the sections on the nav, but for some reason it only includes 1 section then the nav underneath screws up.

-table structure for 'site_pages_cat'-
sectionTitle | sectionName | sectionSide | sectionView sectionInclude | sectionOrder

-example row content-
Site Statistics | stats | R | Y | navStats.php | 1

-navTest3.php-
Code:
<table width="90%" cellpadding="0" cellspacing="0"> 
  <tr> 
    <td width="200" valign="top"> <br /> 
      <?php 
	  		//get the section catergories first
			$q = mysql_query("SELECT `sectionTitle`, `sectionName`, `sectionInclude` FROM `site_pages_cat` WHERE `sectionSide` = 'R' AND `sectionView` = 'Y' ORDER BY `sectionOrder` ASC");
				while(list($sectionTitle,$sectionName,$sectionInclude) = mysql_fetch_row($q)){
		?> 
      <table width="90%" cellpadding="0" cellspacing="0" class="tableBG" align="center" border="1" bordercolor="#CCCCCC" style="border-collapse: collapse"> 
        <tr class="tableBGtitleRow"> 
          <td><strong><?php echo $sectionTitle; ?></strong></td> 
        </tr> 
        <?php
				if($sectionInclude != ""){
			  ?> 
        <tr> 
          <td><?php echo "<script>alert('Page Include: " . $sectionInclude . "');</script>"; include($sectionInclude); //if(!@include($sectionInclude)){ echo "Error In Including Page: <strong>$sectionInclude</strong>"; } ?></td> 
        </tr> 
        <?php
		}
		//now get related links from the site_pages table
		$qLinks = mysql_query("SELECT `title`, `pname`, `externalLink` FROM `site_pages` WHERE `section` = '$sectionName' ORDER BY `pageOrder` ASC");
			while(list($linkTitle,$linkPname,$extLink) = mysql_fetch_row($qLinks)){

		if($linkTitle == ""){
		?> 
        <tr> 
          <td>&nbsp;</td> 
        </tr> 
        <?php
		}
		?> 
        <tr> 
          <td><a href="<?php if($extLink == "N"){ ?>/?p=<?php } else { ?>/?p=out&fwlink=<?php } ?><?php echo $linkPname; ?>"><?php echo $linkTitle; ?></a></td> 
        </tr> 
        <?php
			}//end $qLinks
		?> 
      </table> 
      <br /> 
      <?php
	} //end $q
	  ?> 
      <br /></td> 
  </tr> 
</table> 
</td> 
</tr> 
</table>
-navStats.php-
Code:
<?php 
//number of site hits
$query = mysql_query("SELECT ammount FROM count");
list($dacount) = mysql_fetch_row($query);

//guest and users online
$query2 = mysql_query("SELECT uid FROM online WHERE isuser='no'");
$ammountofnonusersonline = mysql_num_rows($query2);
$query3 = mysql_query("SELECT uid FROM online WHERE isuser='yes'");
$ammountofusersonline = mysql_num_rows($query3);

//people on page
$thePage = $PHP_SELF;
$q = mysql_query("SELECT page FROM online WHERE page = '$thePage'");
$usersonpage = mysql_num_rows($q);
?>
<table width="90%" cellpadding="0" cellspacing="0">
 <tr> 
  <td>Site Hits: <?php echo $dacount; ?></td> 
</tr> 
 <tr> 
  <td>Users Online: <?php echo $ammountofusersonline; ?></td> 
</tr> 
 <tr> 
  <td>Guests Online: <?php echo $ammountofnonusersonline; ?></td> 
</tr>
 <tr>
   <td>People On Page: <?php echo $usersonpage; ?></td>
 </tr> 
</table>

Any Ideas??

Please help and try to fix the problem :)


Regards,

Martin

Computing Help And Info:
 
Are you sure this "while" statement is correct?
Code:
while(list($sectionTitle,$sectionName,$sectionInclude) = mysql_fetch_row($q)){

I would write the loop somewhat differently:
Code:
while ($rw = mysql_fetch_assoc($q)) {

and then anytime you reference $sectionTitle, $sectionName or $sectionInclude, use $rw['sectionTitle'], $rw['sectionName'] and $rw['sectionInclude'].

The same goes for your other "while" loop.

Ken
 
only finds one result from the table?

Only includes navStats.php, no other files?

any ideas?

Regards,

Martin

Computing Help And Info:
 
code looks like this:
Code:
<table width="90%" cellpadding="0" cellspacing="0"> 
  <tr> 
    <td width="200" valign="top"> <br /> 
      <?php 
	  		//get the section catergories first
			$q = mysql_query("SELECT `sectionTitle`, `sectionName`, `sectionInclude` FROM `site_pages_cat` WHERE `sectionSide` = 'R' AND `sectionView` = 'Y' ORDER BY `sectionOrder` ASC");
				//while(list($sectionTitle,$sectionName,$sectionInclude) = mysql_fetch_row($q)){
				while ($rw = mysql_fetch_assoc($q)) {
		?> 
      <table width="90%" cellpadding="0" cellspacing="0" class="tableBG" align="center" border="1" bordercolor="#CCCCCC" style="border-collapse: collapse"> 
        <tr class="tableBGtitleRow"> 
          <td><strong><?php echo $rw['sectionTitle']; ?></strong></td> 
        </tr> 
        <?php
				if($rw['sectionInclude'] != ""){
			  ?> 
        <tr> 
          <td><?php echo "<script>alert('Page Include: " . $rw['sectionInclude'] . "');</script>"; include($rw['sectionInclude']); //if(!@include($sectionInclude)){ echo "Error In Including Page: <strong>$sectionInclude</strong>"; } ?></td> 
        </tr> 
        <?php
		}
		//now get related links from the site_pages table
		$qLinks = mysql_query("SELECT `title`, `pname`, `externalLink` FROM `site_pages` WHERE `section` = '$sectionName' ORDER BY `pageOrder` ASC");
			//while(list($linkTitle,$linkPname,$extLink) = mysql_fetch_row($qLinks)){
			while ($rw2 = mysql_fetch_assoc($qLinks)) {
			
		if($rw2['title'] == ""){
		?> 
        <tr> 
          <td>&nbsp;</td> 
        </tr> 
        <?php
		}
		?> 
        <tr> 
          <td><a href="<?php if($rw2['externalLink'] == "N"){ ?>/?p=<?php } else { ?>/?p=out&fwlink=<?php } ?><?php echo $rw2['pname']; ?>"><?php echo $rw2['title']; ?></a></td> 
        </tr> 
        <?php
			}//end $qLinks
		?> 
      </table> 
      <br /> 
      <?php
	} //end $q
	  ?> 
      <br /></td> 
  </tr> 
</table> 
</td> 
</tr> 
</table>

Regards,

Martin

Computing Help And Info:
 
Have you checked your database to make sure that there is more than one record that will be selected based on your selection criteria?

What happens if you make a test script like:
Code:
<?php
// put in your database connection code here.
$q = mysql_query("SELECT `sectionTitle`, `sectionName`, `sectionInclude` FROM `site_pages_cat` WHERE `sectionSide` = 'R' AND `sectionView` = 'Y' ORDER BY `sectionOrder` ASC");
while ($rw = mysql_fetch_assoc($q)) {
   echo '<pre>';print_r($rw);echo '</pre>'; }
?>
Do you see all of the rows you expect?

If you remove the WHERE condition, do you get all of the rows?

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top