Loop entries

The problem is that he will not go in cycles. There are several results, and I just repeat the results that I get from them. When I use include, it only displays the first record. It can be done. I tried for each, I tried with an array, I tried just to scroll through the results, because I only grab one field, but it will not check all the results, only the first. Thanks.

$connection = mysql_connect($host,$user,$pass);  
mysql_select_db($dbname); 
$sqlr = "select qNumber from regquestions ORDER BY RAND() LIMIT 0,5";
$query = mysql_query($sqlr); 
//$result = mysql_query($sqlr);
while ($rows = mysql_fetch_array($query))
{
include ("q".$rows['qNumber'].".php");
}

using Echo, I get this on the page:

q22.phpq3.phpq17.phpq13.phpq4.php

Using include, I get the first result, which includes one page, but I need it to include all pages.

+4
source share
4 answers

1) , , , $rows ( ). :

other.php:

$rows = 'just a check';

index.php:

$rows = 'somevalue';
include('other.php');
echo $rows; // output: just a check

2) include_once,

+1

Try

include ("'q".$rows['qNumber'].".php'");

OP , , , .

, :

require __DIR__ . '/"q".$rows['qNumber'].".php"';
0

, .

,

include("repeat.php");
for($x=1;$x<10;$x++) 
{ 
echo div($x);
} 

repeat.php

function div($x) {
    return "<div>$x</div>";
} 

<?php
for($x=1;$x<10;$x++)
{
include('repeat2.php');
}  
?>

repeat2.php

 <? //repeat2.php
echo "<div>$x: ".date('H:i:s')."</div>";
sleep(5);
?>

,

0

...

$result = mysql_query("SELECT qNumber FROM regquestions ORDER BY RAND() LIMIT 0,5;") or die(mysql_error());

for($i = 0; $array[$i] = mysql_fetch_assoc($result); $i++);

// Delete last empty one
array_pop($array);

$x = 0;
$end_of_list = count($array)

while ($x < $end_of_list)
{
    include_once("q".$array[$x].".php");
    $x++;
}
0

All Articles