I have a while loop that works exactly the same on three different pages. To make it easier to alter it, I put it in it's own php file, gmldLoop. However, after doing so and including gmldLoop where I'd like it to run on the file, g, it doesn't work. I'm not sure why this is happening. The code is exactly copied and pasted in both files, so I know it's not a typo.
The code that works on g.php:
$query = "SELECT * FROM guidelines ORDER BY sortingLetter ASC, age ASC, category ASC";
$data= mysqli_query($db_conn, $query);
while ($row = mysqli_fetch_array($data)) {
$id = $row['id'];
$age = $row['age'];
$cat = $row['category'];
$title = $row['title'];
$desc = $row['description'];
$ageRange = $row['ageRange'];
$sortingLetter = $row['sortingLetter'];
?>
<section class="content
<?php
switch($ageRange){
case 1:
echo "one";
break;
case 12:
echo "one";
break;
case 123456:
echo "all";
break;
case 2:
echo "two";
break;
case 23:
echo "two three";
break;
case 23456:
echo "two three four five six";
break;
case 3:
echo "three";
break;
case 34:
echo "three four";
break;
case 4:
echo "four";
break;
case 45:
echo "four five";
break;
case 5:
echo "five";
break;
case 56:
echo "five six";
break;
case 6:
echo "six";
break;
case 0:
echo "all";
break;
}
?>"
>
<h2 class="heading noborder">
<div class="title textfloatL">
<small><strong><?php echo $title; ?></strong></small>
</div>
</h2>
<br><br>
<div class="sqldata">
<div class="desc">
<?php echo $desc; ?>
</div>
<div class="agesdiv incap textfloatR">
<p class="inup">
<small><?php if (!$age) {
echo 'All Ages';
} else {
echo $age;
} ?></small>
</p>
|
<p class="incap">
<small><?php echo $cat; ?></small>
</p>
</div>
<br>
</div>
</section>
<?php
}
?>
The code from gmldLoop :
$data= mysqli_query($db_conn, $query);
while ($row = mysqli_fetch_array($data)) {
$id = $row['id'];
$age = $row['age'];
$cat = $row['category'];
$title = $row['title'];
$desc = $row['description'];
$ageRange = $row['ageRange'];
$sortingLetter = $row['sortingLetter'];
?>
<section class="content
<?php
switch($ageRange){
case 1:
echo "one";
break;
case 12:
echo "one";
break;
case 123456:
echo "all";
break;
case 2:
echo "two";
break;
case 23:
echo "two three";
break;
case 23456:
echo "two three four five six";
break;
case 3:
echo "three";
break;
case 34:
echo "three four";
break;
case 4:
echo "four";
break;
case 45:
echo "four five";
break;
case 5:
echo "five";
break;
case 56:
echo "five six";
break;
case 6:
echo "six";
break;
case 0:
echo "all";
break;
}
?>"
>
<h2 class="heading noborder">
<div class="title textfloatL">
<small><strong><?php echo $title; ?></strong></small>
</div>
</h2>
<br><br>
<div class="sqldata">
<div class="desc">
<?php echo $desc; ?>
</div>
<div class="agesdiv incap textfloatR">
<p class="inup">
<small><?php if (!$age) {
echo 'All Ages';
} else {
echo $age;
} ?></small>
</p>
|
<p class="incap">
<small><?php echo $cat; ?></small>
</p>
</div>
<br>
</div>
</section>
<?php
}
?>
The code in g.php if I use the include 'gmldLoop.php' :
<?php
$query = "SELECT * FROM guidelines ORDER BY sortingLetter ASC, age ASC, category ASC";
include $_SERVER["DOCUMENT_ROOT"] . '/inc/pageStructure/gmldLoop.php';
?>