[PHP] I only want x number of lines of data

2006-08-09 Thread Ross
At the mometn I have this


function display_result($module_no) {

if ($module_no != ) {
$module_no =unserialize ($module_no);
foreach ($module_no as $number = $data) {

$count=$count+1;?

Q.?=$count; ?- span style=font-weight:bold?=$data;?/spanBR /
?
}
}

which outputs all the data in the array..typically..

Q.1- pass
Q.2- pass
Q.3- pass
Q.4- pass
Q.5- pass


but what if i only want q1-q3 output? any ideas how I can modify the script 
to give me x number of outputted answers? 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I only want x number of lines of data

2006-08-09 Thread Brad Bonkoski



Ross wrote:

At the mometn I have this


function display_result($module_no) {

  

   $count = 0; //Of course you *should* initialize $count
   $start = 1;
   $end = 3;

if ($module_no != ) {
$module_no =unserialize ($module_no);
foreach ($module_no as $number = $data) {

$count=$count+1;

  

   if( $count = $start  $count = $end ) { ?

Q.?=$count; ?- span style=font-weight:bold?=$data;?/spanBR /
  
?
  

   }

}
  
}


which outputs all the data in the array..typically..

Q.1- pass
Q.2- pass
Q.3- pass
Q.4- pass
Q.5- pass


but what if i only want q1-q3 output? any ideas how I can modify the script 
to give me x number of outputted answers? 

  


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I only want x number of lines of data

2006-08-09 Thread Jochem Maas
? phpinfo(); ?PROMISE? phpinfo(); ?TO? phpinfo(); ?STOP? phpinfo(); 
?BREAKING? phpinfo(); ?IN? phpinfo();
?AND? phpinfo(); ?OUT? phpinfo(); ?OF? phpinfo(); ?PHP? phpinfo(); 
?TO? phpinfo(); ?OUTPUT? phpinfo();
?STRINGS? phpinfo(); ?TO? phpinfo(); ?THE? phpinfo(); ?BROWSER? 
phpinfo();

evil_grineasy to read don't you think?/evil_grin

Ross wrote:
 At the mometn I have this
 
 
 function display_result($module_no) {
 
 if ($module_no != ) {
 $module_no =unserialize ($module_no);
 foreach ($module_no as $number = $data) {
 
 $count=$count+1;?

why $count when you already have $number

 
 Q.?=$count; ?- span style=font-weight:bold?=$data;?/spanBR /
 ?
 }
 }

function display_result($module_no, $max = null)
{
if (is_string($module_no)  $module_no)
$module_no = unserialize($module_no); // god knows why your 
using this
if (!is_array($module_no)) return;

if (!$max || !is_int($max)) $max = count($module_no);

$count = 0;
foreach ($module_no as $number = $data) {
if ($count  $max) break;
echo Q., $count++,' - strong',$data,'/strongbr /';
}
}


PS - generally is better when function don't echo stuff... it makes them
more flexible.
 
 which outputs all the data in the array..typically..
 
 Q.1- pass
 Q.2- pass
 Q.3- pass
 Q.4- pass
 Q.5- pass
 
 
 but what if i only want q1-q3 output? any ideas how I can modify the script 
 to give me x number of outputted answers? 

hunderds - see simple idea number one above to get started.

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I only want x number of lines of data

2006-08-09 Thread Robert Cummings
On Wed, 2006-08-09 at 16:39 +0200, Jochem Maas wrote:
 ? phpinfo(); ?PROMISE? phpinfo(); ?TO? phpinfo(); ?STOP? phpinfo(); 
 ?BREAKING? phpinfo(); ?IN? phpinfo();
 ?AND? phpinfo(); ?OUT? phpinfo(); ?OF? phpinfo(); ?PHP? phpinfo(); 
 ?TO? phpinfo(); ?OUTPUT? phpinfo();
 ?STRINGS? phpinfo(); ?TO? phpinfo(); ?THE? phpinfo(); ?BROWSER? 
 phpinfo();
 
 evil_grineasy to read don't you think?/evil_grin
 
 Ross wrote:
  At the mometn I have this
  
  
  function display_result($module_no) {
  
  if ($module_no != ) {
  $module_no =unserialize ($module_no);
  foreach ($module_no as $number = $data) {
  
  $count=$count+1;?
 
 why $count when you already have $number

And even if you really want to use $count, why not use the faster +=
operator:

$count += 1;

Or if 1 is always going to be your increment:

$count++;

Or if you know how ++ works and want to eke just a tad more speed out:

++$count;

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php