Hello Every on i have wrote some scripts for my website and i am getting Undefined variable Notices on a couple Variables like exampled below

$i = 0;
foreach($value as $row) {
  $content .= "<option value=\"".$i."\" ".$selected.">".$row."</option>\n";
  $i++;
}

now every time i view the page with the error_reporting off it shows this

Notice: Undefined variable: content

dose any know how i can fix this problem??? it would really help

Hello Every on i have wrote some scripts for my website and i am getting Undefined variable Notices on a couple Variables like exampled below

$i = 0;
foreach($value as $row) {
  $content .= "<option value=\"".$i."\" ".$selected.">".$row."</option>\n";
  $i++;
}

now every time i view the page with the error_reporting off it shows this

Notice: Undefined variable: content

dose any know how i can fix this problem??? it would really help

use

ob_start()

.

The error is there is no variable named content like $content. Set the $content variable. Here it is:

$i = 0;
$content;
foreach ($value as $row) {
$content .= "<option value=\"" . $i . "\" " . $selected . ">" .$row . "</option>\n";
$i++;
      }

But there is no print result for above codes. What do you want for?
Do you want to print out the options. Try this

$i = 0;
echo "<select name=\"selectItem\">";
foreach($value as $row) {
echo "<option value=\"" . $i . "\">" . $row . "</option>\n";
$i++;
}
echo "</select>";

Good luck..

no i don't want to print out i got this covered it is the area that the script has a notice warring of undefined variable other wise it works fine im just trying to get the notice warring off there with out using error_reporting to hide the notice warring ok I'm using stackable variables for the print out so ya got that covered but that is where the error is occurring at on the foreach loop the stackable var is like example

$content .= "";

that were in the loop the notice warring is showing up on any var with the .= show up with the notice warring now can i get any help if i explained it well enough

It is the same below.

$content = "Hello From ";
//$content has the value "Hello From" string

$content .= "My PHP Page";
//Now, $content has the value "Hello From My PHP Page" string

It assign the variable to its value and another values. I can't explain very well because of I'm newer of PHP. Go there and it will teach you much more. Cheer..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.