PHP variable scope headache
-
ok, I thought it was a good idea but I’m starting to wonder…
I created 2 files, one news.php and one calendar.php with a short version of the regular index.php code plus a
on top of each file with the x replaced by the “news” and “calendar” category IDs respectively. I get the desired effect when I access each file individually through my browser: one shows all the “news” and the other all the “calendar” events…
$cat = x;
Only problem is, what I wanted to do was to include both file in ahome.php
page with a<?php include 'directory/news.php'; ?>
type thing.
What happens is that the firstinclude
is just fine, but the second outputs the “Sorry, no posts matched your criteria.” part of the conditional statement.
I don’t know much about programming but I was guessing that maybe theif ($posts)
conditional always returns false because the variables have still values from the previousinclude
so I tried resetting those variables but my syntax might be wrong or I’m just missing the point… Not sure.
Any PHP guru in the house yo?! ??
- The topic ‘PHP variable scope headache’ is closed to new replies.