Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:31:20+00:00 2026-05-30T00:31:20+00:00

I just finished writing this script and getting it to work but I need

  • 0

I just finished writing this script and getting it to work but I need to use it a total of 8 times on 1 page. It works fine the first time but the second time I get: Fatal Error cannot redeclare get_names(). I’ve been told the way around this is to use include_once but I can’t seem to figure out how exactly I’m supposed to do that. I’ve tried cutting both of the get_names parts out of the code and putting them into separate php files then using the include_once command. I got it to work but once again I got the same error after trying to use the script twice. I also tried putting the whole script into a php file and then using the include_once(“scriptname.php”) command and the same thing happened. So my questiion is how exactly do I cut this script up so I don’t get this error anymore?

<?php
$db = mysql_connect('localhost', 'username', 'pass') or die("Database error");
mysql_select_db('dbname', $db);

$query = "SELECT pool FROM winners";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
if ($row['pool'] % 2) {
echo "<h4>Result 1</h4>";
$names = get_names(1);
foreach($names as $name) {
    echo $name . "<br/>";
}
} else {
echo "<h4>Result 2</h4>";
$names = get_names(0);
foreach($names as $name) {
    echo $name . "<br/>";
}
}

function get_names($pool_result)
{
$name_array = array();

$query = "SELECT * FROM comments WHERE commentid % 2 = $pool_result";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
array_push($name_array, $row['name']);
}

return $name_array;

} ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:31:22+00:00Added an answer on May 30, 2026 at 12:31 am

    put getNames function in afile.php and include that once at the start. take getNames function out of your current file.

    so things goes like this

    in first php file (say) you have this code – filea.php

     function get_names($pool_result)
     {
     $name_array = array();
    
    $query = "SELECT * FROM comments WHERE commentid % 2 = $pool_result";
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_array($result)) {
    array_push($name_array, $row['name']);
     }
    
    return $name_array;
    
    }
    

    you second file will have fileb.php

     $db = mysql_connect('localhost', 'username', 'pass') or die("Database error");
     ..... rest of source code excluded. Make sure you get rid of getNames in this file
    

    Now just include as per normal

    include 'filea.php'; // include it once only
    
    
    include 'fileb.php'; // as many times as your wish
    

    or just wrap your code in a function and call that instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just about finished writing a backend for a website in PHP/MySQL/jQuery, but my
I just finished writing my own collecion class, and i'd really like to make
Just finished read this post by Greg Young, where he is talking about Microsoft
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
I just finished a small project where changes were required to a pre-compiled, but
I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after
I want to run a shell script in php, but this shell script takes
As a developer who has just finished writing thousands of lines of complex multi-threaded
As a programming exercise, I just finished writing a Sudoku solver that uses the
I'm writing a simulation of Bananagrams for fun. I want to use concurrency but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.