On Tue, 13 Feb 2001 15:24, andrew wrote:
> Hi - I want to print a list of numbers linked to URLs I create on the
> fly - something like this:
>
> table:
> -------------------
> path pid
> ---------|---------
>
> foo.jpg 1
> bar.jpg 1
>
> <?php
>
> include("db_connection_params.inc"); //all relevant database variables
> $sql="select path from table where pid =1"; //obvious
> $link_id = mysql_connect($host, $usr, $pass); //get connection handle
>
> $result = mysql_db_query($database, $sql, $link_id);
> $count = mysql_num_rows($result) or die ("no rows returned from $sql");
>
> $i = 0; //initialze counter
>
> for (0 < $i > $count; $currrent_row = mysql_fetch_row($result); ++$i;)
I think you want something more like
for($i = 0; $i < $count; $i++)
{
$current_row = mysql_fetch_row($result);
>
> {
>
> $path=$current_row[2]"; //database field position matched index
> number print "<a href = $path>$count</a><br>"; //
Instead of this, you could do
extract($current_row);
echo "<a href = $path>$count</a><br>";
> }
>
> ?>
>
> so I want this to print:
> 1 (linked to foo.jpg)
> 2 (linked to bar.jpg)
>
> The problem is I'm getting a parse error on the "for" line.
>
> Any ideas?
>
> TIA,
> andrew
Or a slightly more elegant solution:
include("db_connection_params.inc"); //all relevant database variables
$sql="select path from table where pid =1"; //obvious
$link_id = mysql_connect($host, $usr, $pass); //get connection handle
$result = mysql_db_query($database, $sql, $link_id);
/* put a die on the above or better use mysql_error */
$i = 1; //initialise counter
while($row=mysql_fetch_array($result)){
extract($row);
echo "<a href=\"$path\">$i</a><br>";
$i++;
}
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA
--
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]