Hi,

can anyone suggest how to make this less hackish - perhaps preserving the
array across page iterations somehow?

I'm storing image path info in MySQL and creating an array from the result
set, so I can build hrefs to the other pics as well as populate the img tag.
This page calls itself to provide a running display of the current pic and
the links to other pics.
To preserve the passed href value, I've had to create the array TWICE as
well as map the passed variable to another name to preserve it.

tia,
andrew

<?php
//begin database connection stuff
include("db_connect_params.inc");  //all relevant database variables
$sql="select path from PHOTO where pid =1";  //obvious
$link_id = mysql_connect($host, $usr, $pass); //get connection handle
$result = mysql_db_query($database, $sql, $link_id) or die("no result");

//begin hackishness
if (!isset($i))
{
 $i = 1; //initialize counter
 while($row=mysql_fetch_array($result)) //read rows of picture paths into an
array
   {
    extract($row);
    $displayed[$i]=$path;
    echo "<a href=\"$PHP_SELF?i=$i\">$i</a>&nbsp&nbsp";
    $i++;
   }

 echo "<img src =\"$displayed[1]\"></img><br>"; //use first row pic as
default

} else {

           $ii = $i; //preserve passed pic selection value
           $i = 1; //re-initialize counter
           while($row=mysql_fetch_array($result)) //read rows of picture paths
into an array
                {
                 extract($row);
                 $displayed[$i]=$path;
                 echo "<a href=\"$PHP_SELF?i=$i\">$i</a>&nbsp&nbsp";
                 $i++;
                }

           echo "<img src =\"$displayed[$ii]\"></img><br>"; //use passed pic

       }

?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to