You are here:  » Question about Notice: Undefined index: view

Support Forum



Question about Notice: Undefined index: view

Submitted by Capricorn on Sun, 2012-10-28 13:06 in

Hi David,

While experimenting with the SearchResultsGridList files, I noticed that if I disable the // error_reporting(E_ERROR); in the config.php script, I would get this on my search page: Notice: Undefined index: view in F:\xampp\htdocs\store\html\searchresults.php on line 5

I tried a new search.php and searchresults.php from the new SearchResultsGridList.zip in order to have a clean code, but that Notice: still shows up if I disable the error_reporting(E_ERROR).

I think it may be something simple to fix, because in "Grid View" that Notice: doesn't show on any page of the navigation, but while on "List View", it shows up on every page.

That Notice: refers to this line: "if ($_GET["view"]=="grid"):" on the searchresults.php script.

I tried experimenting with: "if (isset($_GET["view"])=="grid"):" on the searchresults.php script, and while that will remove the Notice: from the results of the "List View", I wonder if that extra code I added may break something else later.

So my question is:

Is there another way to get rid of that Notice: without having to add error_reporting(E_ERROR); to config.php or the "isset" code I added there?

Thanks.

Submitted by support on Mon, 2012-10-29 09:24

Hi Capricorn,

Have a go with:

  if (isset($_GET["view"]) && ($_GET["view"]=="grid"))

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Mon, 2012-10-29 16:04

Hi David,

I had to add the : to the end of =="grid")): and now it it works perfect.

But, now I found another little bug.

Sorry to bother you again but, since you're a genius with the code, I will ask you another question related to the search.php code, I already tried a few experiments and I still can't find what's wrong.

After doing some final checks on the local site with the the // error_reporting(E_ERROR); disabled, I discovered that if I use the search box to search for any keyword, I wiil get this Notice error on the top of the page:

Notice: Undefined offset: 1 in F:\xampp\htdocs\store\search.php on line 397

On line 397 of search.php I have this line: if($parts[1])

And if I block that entire section:

if($parts[1])
{
$header["meta"]["description"] = $parts[1]." product catalog index";
$header["meta"]["keywords"] = $parts[1].", ".$parts[0]." ". "products";

if ($page > 1) $header["meta"]["description"] .= " page ".$page;
}

I don't get the Notice error, so I think something must be missing in that section of the code.

If I enable the error_reporting(E_ERROR); in config.php I would not get the Notice error, and the scipt will work, but I am trying to keep the search.php code as clean as possible in order to avoid any errors in any future updates or modifications.

Thanks.

Submitted by support on Tue, 2012-10-30 09:55

Hi,

If you replace line 397:

 if($parts[1])

...with:

 if ((isset($parts[1])) && ($parts[1]))

...that should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Tue, 2012-10-30 18:33

Working perfect!

Thanks.