villain222 Posted October 16, 2007 Share Posted October 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73550-solved-fatal-error-cannot-redeclare-myfunction/ Share on other sites More sharing options...
MadTechie Posted October 16, 2007 Share Posted October 16, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73550-solved-fatal-error-cannot-redeclare-myfunction/#findComment-371092 Share on other sites More sharing options...
villain222 Posted October 17, 2007 Author Share Posted October 17, 2007 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??? Quote Link to comment https://forums.phpfreaks.com/topic/73550-solved-fatal-error-cannot-redeclare-myfunction/#findComment-371306 Share on other sites More sharing options...
MadTechie Posted October 17, 2007 Share Posted October 17, 2007 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>' ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73550-solved-fatal-error-cannot-redeclare-myfunction/#findComment-371552 Share on other sites More sharing options...
villain222 Posted October 17, 2007 Author Share Posted October 17, 2007 MadTechie, you're my hero. thanks it worked like a charm. Essentially I'm pulling forward Items that a user has available for others to view. The progress bar goes along with each separate item. Thanks for the Help. Quote Link to comment https://forums.phpfreaks.com/topic/73550-solved-fatal-error-cannot-redeclare-myfunction/#findComment-371855 Share on other sites More sharing options...
MadTechie Posted October 17, 2007 Share Posted October 17, 2007 Glade i could help Quote Link to comment https://forums.phpfreaks.com/topic/73550-solved-fatal-error-cannot-redeclare-myfunction/#findComment-371864 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.