Fatal error: Cannot redeclare function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Fatal error: Cannot redeclare function

Post by bla5e »

Code: Select all

       while($row = mysql_fetch_array($result)) {
            echo ("<form action=\"makeMoney.php?id=edit\" method=\"post\">");
            function getRest() {
            echo ("<th width=\"156\" scope=\"col\">" . $row['fullname'] . "</th>");
            echo ("<th width=\"367\" scope=\"col\">" . $row['name'] . "</th>");
            echo ("<th width=\"121\" scope=\"col\">" . $row['status'] . "</th>");
            echo ("<th scope=\"col\" align=\"left\">");
            echo ("<select name=\"edit\" id=\"jumpMenu\">");
            echo ("<option>Not Started</option><option>Downloaded</option><option>Burned</option><option>Sold</option>");
            echo ("<input type=hidden name=forWho value=".$row['id'].">");
            echo ("<input type=\"submit\" value=\"Submit\">");
            echo ("</form>");
            echo ("</th></tr>");
            }
            if ("" . $row['status'] . ""  == "Not Started") { echo ("<tr bgcolor=\"Red\">"); getRest(); }
            elseif ("" . $row['status'] . ""  == "Downloaded") { echo ("<tr bgcolor=\"Orange\">"); getRest(); }
            elseif ("" . $row['status'] . ""  == "Burned") { echo ("<tr bgcolor=\"Yellow\">"); getRest(); }
            elseif ("" . $row['status'] . ""  == "Sold") {  }
            
        }  
Im trying to get it so it doesnt display items listed as sold.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Fatal error: Cannot redeclare function

Post by Burrito »

you're recreating the function with every iteration of your while loop...can't do that.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Re: Fatal error: Cannot redeclare function

Post by bla5e »

yeah i also tried to remove it from the loop, then it wouldnt display any data because the loop consists of my mysql fetch
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Fatal error: Cannot redeclare function

Post by Burrito »

put your function declaration outside of your loop and call your function within your loop and pass in the arguments you need it to process.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Re: Fatal error: Cannot redeclare function

Post by bla5e »

Here is my current code I am using, but its sill not working.
I am getting no errors, but its not displaying any data from the function.

Code: Select all

 
case 'current':
        $con = mysql_connect("xx ", "xx ", "xx ") or die(mysql_error());    
        mysql_select_db("xx", $con);    
        $result = mysql_query("SELECT * FROM makeMoney");
        
        function getRest($data) {
            echo ("<th width=\"156\" scope=\"col\">" . $data['fullname'] . "</th>");
            echo ("<th width=\"367\" scope=\"col\">" . $data['name'] . "</th>");
            echo ("<th width=\"121\" scope=\"col\">" . $data['status'] . "</th>");
            echo ("<th scope=\"col\" align=\"left\">");
            echo ("<select name=\"edit\" id=\"jumpMenu\">");
            echo ("<option>Not Started</option><option>Downloaded</option><option>Burned</option><option>Sold</option>");
            echo ("<input type=hidden name=forWho value=".$data['id'].">");
            echo ("<input type=\"submit\" value=\"Submit\">");
            echo ("</form>");
            echo ("</th></tr>");
        }
        
        echo ("<center><h3> Currenty Requested</h3>");
        echo ("<table width=893 border=1 cellspacing=0 cellpadding=0 bordercolor=\"#000000\">");
        echo ("<tr>");
        echo ("<th width=\"156\" scope=\"col\">Client</th>");
        echo ("<th width=\"367\" scope=\"col\">Item Requested</th>");
        echo ("<th width=\"121\" scope=\"col\">Status</th>");
        echo ("<th width=\"121\" scope=\"col\"></th>");
        echo ("</tr>");
        while($row = mysql_fetch_array($result)) {
            echo ("<form action=\"makeMoney.php?id=edit\" method=\"post\">");
            if ("" . $row['status'] . ""  == "Not Started") { echo ("<tr bgcolor=\"Red\">"); getRest($data); }
            if ("" . $row['status'] . ""  == "Downloaded") { echo ("<tr bgcolor=\"Orange\">"); getRest($data); }
            if ("" . $row['status'] . ""  == "Burned") { echo ("<tr bgcolor=\"Yellow\">"); getRest($data); }
            if ("" . $row['status'] . ""  == "Sold") { echo ("<tr bgcolor=\"Green\">"); }
        }
        echo ("</table></form></center>");
    break;
 
any ideas? Thanks in advance
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Re: Fatal error: Cannot redeclare function

Post by bla5e »

nevermind it was because the rows were mislabeled in my database
Post Reply