p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Help!!


Message #1 by WH Micro <wh_micro@y...> on Wed, 29 May 2002 12:18:53 -0700 (PDT)
Hi All:

I am having a little problem:

I am trying to load a file's path from a DB and store
the record_id on an array. That way the next time the
function is called I don't get a repeated file into
the page. In other words, I'm trying to simulate
randomized links to be included on the page but, I
don't want it to repeat.


$path='NULL';
$text = array( 2, 3, 6, 9 );
$currentPath = 1;

//the function gets called from different places
several times like this: 
<tr>
<td><? get_file( $currentPath++ ); include($path); ?>
</td>
</tr>


function get_file($cur){
   global $path, $text;
   if( $cur == 1 )
    {
     $id = rand( 1, 10 );
     $sql = "select path from table where rec_id=$id";
     $result = runQuery( $sql );
     ..... database functions work .......
     $text[1]=$id;
     list( $path ) = mysql_fetch_array($result);
    }
   else
    {
     while( !checkId( $id=rand( 1, 10 ) ) )
      {
        $id = rand( 1, 10 );
     $sql = "select path from table where rec_id=$id";
     $result = runQuery( $sql );
     ..... database functions work .......
     $text[$cur]=$id;
     list( $path ) = mysql_fetch_array($result);
}
    }
}// endFunction

function checkId( $id )
{
  global $text;

   for($i=1; $i<5; $i++ )
   {
    if( $text[$i]==$id )
     print( 'Compared...' );
     return true;
   }
   return false;

}

Some how the print statement in the checkId() never
gets executed. I don't know why. What am I doing
wrong?

Please help.

Thanks.

=====
www.whmicro.com

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

  Return to Index