0

I have a problem with getting MySQL column into php array variable , for further foreach() cycling.

Here is my code:

$files=array();
$filesFetch = "SELECT FileName FROM articledata";
$rs=mysql_query($filesFetch);
while($rd=mysql_fetch_object($rs))
{
$files[]=$rd->files;
}

if (!$files) {
    die('getting filenames failed');
}
foreach ($files as $key => $id) 
{  //... do the stuff }

I am not getting stopped at the die condition, but my error says:

Notice: Undefined property: stdClass::$files

I assume there is problem with formatting, because this error notice repeats :"rowCountTimes"

Also this error appears for the line.

$files[]=$rd->files;
1

4 Answers 4

2

Your object has properties based on the column names; you need to use:

$files[]=$rd->fileName;
Sign up to request clarification or add additional context in comments.

Comments

0

You are fetching FileName, so you must use that in your object:

$files[]=$rd->FileName;

1 Comment

Thank You , same as the guys above
0

It should be

$rd->FileName

instead of $rd->files since your column name is FileName

Comments

0

The code you wrote certainly doesn't make sense. You are fetching an object which is saved in a variable $rd. Then you are trying to access property files but of course that is undefined since you only fetched the column named FileName.

So use instead: $files[] = $rd->FileName;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.