help make less ugly?
| From: | Andrew | Date: | Wed, 14 Feb 2001 22:19:11 +0000 |
| Subject: | help make less ugly? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-39763@lists.php.net to get a copy of this message | ||
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>  ";
$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>  ";
$i++;
}
echo "<img src =\"$displayed[$ii]\"></img><br>"; //use
passed pic
}
?>