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

  • Home
  • SEARCH
  • 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 6810971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:16:12+00:00 2026-05-26T20:16:12+00:00

I have a question regarding applying a custom function to mysql_fetch_assoc while it is

  • 0

I have a question regarding applying a custom function to mysql_fetch_assoc while it is in the while loop. See code below.

//current php page
$query = mysql_query("SELECT ... "); //returns multiple rows

while($rs = whileF($query)) {

    //do some fantastic stuff

}

//... functions.php page

function whileF($value = array()) {
    $var = mysql_fetch_assoc($value);

    foreach($var AS $k => $v) {
        $var[$k] = stripslashes($v);
    }

    return $var;
}

My question is I’d like to be able to automatically strip the slashes our of the different fields with this type of a function (and I’d also like to record some debug data if necessary), but it doesn’t seem to cooperate too well. If I do a..

print_r($var);

it will return all the values in an array, but by doing the foreach statement I keep getting “Warning: Invalid argument supplied for foreach() in /home/…/includes/functions.php” and if I try this…

$var = array_map('stripslashes',$var);

I get “Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/…/includes/functions.php”

The odd part is, it seems like it applies the foreach/array_map functions properly (the values are being stripped). I don’t want to turn off errors, just to make them go away as that would be……less effective programming. I know that the whileF() function works properly cause it’s still displaying all the info and if I take away the foreach/array_map statements it’ll run without any errors.

Thoughts? I know I’m missing something……

Thanks in advance.

  • 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-26T20:16:13+00:00Added an answer on May 26, 2026 at 8:16 pm

    That’s because the last call to mysql_fetch_assoc returns false. You should wrap the foreach in an if:

    function whileF($value = array()) {
        $var = mysql_fetch_assoc($value);
        if ($var) {
           foreach($var AS $k => $v) {
                $var[$k] = stripslashes($v);
           }
        }
        return $var;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding static function in php. let's assume that I have
I have a question regarding restricted pointer assignments. See the comments in code for
I have question regarding the use of function parameters. In the past I have
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a question regarding handling errors in a J2EE application. Our current application
I have a question regarding threading in Java. In my code, ... client.doSth(); //
I have a question regarding toFixed() function. If I have a float e.g. -
I have a question regarding this code. I'm a beginner and enjoy learning C#.
I have a question regarding the std::sort algorithm. Here is my test code: struct
I have a question regarding data transmission from php to javascript. I gather some

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.