Jump to content

[SOLVED] Fatal error: Cannot redeclare myfunction()


villain222

Recommended Posts

I'm a big newb so i need some help with an include i'm trying.  the include works inside of an array (maybe that is part of the problem).  It is to call up a progress bar that coincides with the items listed in array. Here is the page it  with the include.  It's sloppy but aside from my problem it works:

 

$sessionid = $_SESSION['userid'];

}

//$join = "SELECT items.*, image.* ". COPIED FORMAT

// "FROM items, image ".

// "WHERE items.imageid = image.id".

// "AND items.userid = $sessionid";

$join = "SELECT items.*, image.* FROM items, image WHERE items.imageid = image.imageid AND items.userid = $sessionid";

 

 

 

?><strong><?

$PicSQL = mysql_query($join)or die(mysql_error());

while ($row=mysql_fetch_array($PicSQL)) {

echo $row['name']; ?><br><?

echo $row['descrip']; ?><?

//echo $row['imagename']; ?><br><?

echo "<img src=\"/dev/uploads/". $row['imagename'] ."thumbnail\">";

//echo $row['imageid']; ?><br>Price: <?

echo $row['price']; ?><?

$itemImg = $row['imageid'];

$itemid = $row['id'];

include ("raffleprogresstemp.php");?><hr><?[/font]

}

 

 

Here is the included page:

 

<?

 

$progSQL = mysql_query("SELECT items.*, tickets.* FROM items, tickets WHERE items.id = tickets.item AND items.id = $itemid");

while($row6=mysql_fetch_array($progSQL)){

$price = $row6['price'];

//echo $row['price'];

$number=mysql_num_rows($progSQL);

//echo "total tickets sold= ". $number;?><br><?

}

 

//$query = mysql_query("SELECT * FROM student");  EXAMPLE

//$number=mysql_num_rows($query);

//echo "Total records in Student table= ". $number;

 

function progressBar($price, $number)  This is the Line 15 of the Error

{

$percentage=$number / $price * 100;

echo '<table cellpadding=1 cellspacing=1 border=1 width=100><TR><td><img src="images/bar.jpg" height=10 width='.$percentage.'></td></TR></table>' ;

}

progressBar($price, $number);

 

?>

 

The Error Message is:

 

Fatal error: Cannot redeclare progressbar() (previously declared in /home/.tarry/bampow/bampow.com/dev/raffleprogresstemp.php:15) in /home/.tarry/bampow/bampow.com/dev/raffleprogresstemp.php on line 15

 

Please Help me out.

welcome to the board

try this

change

include ("raffleprogresstemp.php");?>

to

include_once ("raffleprogresstemp.php");?>

 

bascially that file has been included before.. so PHP is confused why you have 2 or more functions called "progressbar", so you need to tell php that if it already included don't include it again.. this is called include_once :) you can do the same for require (require_once), the only differents is require mean the page will fail to load the rest of the page, if that required file isn't "included".. thus its called require ;)

 

good luck and happy PHPing

ok, I tried it, but basically i need it to repeat with each result posted from the array. The Include_once worked as far as getting rid of the error, but not the result I'm looking for.  I wondering if I should join the table needed for the progress bar and build it into the array.  That would be the hard way as this is not the only page I need this to work with.  Is there any other options???

i am not 100% sure what your trying to do but.. heres a clean version..

it may work..

 

<?php
$sessionid = $_SESSION['userid'];

$join = "SELECT items.*, image.* FROM items, image WHERE items.imageid = image.imageid AND items.userid = $sessionid";


include_once "raffleprogresstemp.php";	
echo "<strong>";
$PicSQL = mysql_query($join)or die(mysql_error());
while ($row=mysql_fetch_array($PicSQL))
{
echo $row['name']."<br>"; 
echo $row['descrip']."<br>"; 
//echo $row['imagename'];
echo "<img src=\"/dev/uploads/". $row['imagename'] ."thumbnail\">";
//echo $row['imageid']; 
echo "<br>Price: ";
echo $row['price'];
$itemImg = $row['imageid'];
$itemid = $row['id'];
ShowPB($itemid);
echo "<hr>";
}


?>

 

 

<?php

function ShowPB($itemid)
{
if($itemid <0) return;
$progSQL = mysql_query("SELECT items.*, tickets.* FROM items, tickets WHERE items.id = tickets.item AND items.id = $itemid");


//Not sure what your trying to do here??? 
//but it will only get the LAST value...
/* 	while($row6=mysql_fetch_array($progSQL))
* 	{
* 		$price = $row6['price'];
* 		$number=mysql_num_rows($progSQL);
* 		//echo "total tickets sold= ". $number;
* 		echo "<br>";
* 	}
*/
//Revised version of above
$row6=mysql_fetch_array($progSQL);
$price = $row6['price'];
$number=mysql_num_rows($progSQL);
//echo "total tickets sold= ". $number;
echo "<br>";
progressBar($price, $number);
}

function progressBar($price, $number)
{
$percentage=($number / $price) * 100;
echo '<table cellpadding=1 cellspacing=1 border=1 width=100><TR><td><img src="images/bar.jpg" height=10 width='.$percentage.'></td></TR></table>' ;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.