Home>

There is a home page of the site -see> https://jsfiddle.net/vladdvin/e120g4sq/3/. By clicking on the left side menu item, the right side menu and the central part using AJAX should be displayed. Below is part of the code from the page - http://testsite.ru/stackoverflowite/html/testsite.html.

Let SubcategoryFlag= ''; ≪
! -Subcategory menu ->
        Console.log (SubcategoryFlag); ≪
! -Debugging ->
            $ ('. submenu__item a'). ON ('Click', Function (Event) {
                event.preventDefault ();
                Console.log ('Inner Check'); <
! -Debugging ->
                subcategoryflag= event.target.innerhtml; ≪
! -Assigning text Subcategory menu ->
                $.ajax ({
                    Method: 'Post',
                    URL: '../PHP/ajaxSubcategory1.php',
                    Cache: False,
                    Data: {SubcategoryFlag: SubcategoryFlag},
 ≪
! -reference to the server subcategory menu, depending on which the server sets the right side menu ->
                    Datatype: 'Json',
                    Complete: FUNCTION (DATA) {<
! -Debugging Ajax ->
                        Console.log (Data.header);
                        Console.log (data.countRecords);
                    }
                    SUCCESS: FUNCTION (DATA) {
                        Console.log ('Check'); <
! -Debugging ->
                        Console.log (DATA); <
! -Debugging ->
                        $ ('. RightMenu'). HTML (Data.msg);
                        $ ('. Centerea'). HTML ('<
DIV ID= \ "TOPCENERAREA \" >
'+' ≪
H1 >
'+ Data.Header +' <
/h1 >
'+ Data.countRecords +' Goods '+' <
/div >
'); ≪
! -Assigning the right side menu ->
                        //ExpandCollapsedFunction ();
                }
            }
            );
        }
        );
        //the same code as the code above -only for black items menu of the monoblock type
        Let CategoryFlag= '';
            $ ('. submenu__title a'). ON ('Click', Function (EVENT) {
                event.preventDefault ();
                Console.log ('Inner Check');
                CategoryFlag= event.target.innerhtml;
                SubcategoryFlag= CategoryFlag;
                Console.log (CategoryFlag);
                $.ajax ({
                    Method: 'Post',
                    URL: '../PHP/ajaxSubcategory1.php',
                    Cache: False,
                    Data: {CategoryFlag: CategoryFlag, SubcategoryFlag: SubcategoryFlag},
                    Datatype: 'Json',
                    Complete: FUNCTION (DATA) {
                        Console.log (Data.header);
                        Console.log (data.countRecords);
                    }
                    SUCCESS: FUNCTION (DATA) {
                        Console.log ('Check');
                        Console.log (DATA);
                        $ ('. RightMenu'). HTML (Data.msg);
                        $ ('. Centerea'). HTML ('<
DIV ID= \ "TOPCENERAREA \" >
'+' ≪
H1 >
'+ Data.Header +' <
/h1 >
'+ Data.countRecords +' Goods '+' <
/div >
');
                        //ExpandCollapsedFunction ();
                }
            }
            );
        }
        ); 
<
? php.
Class AjaxValidate {
    FUNCTION FORMVALIDATE () {
        //Put Form Elements INTO POST VARIABLES (This Is Wower You Would Sanitize Your Data)
        $ CategoryFlag= $ _ POST ['CategoryFlag'];$ subcategoryflag= $ _post ['subcategoryflag']; //Establish Values ​​That Will Be Returned Via Ajax
        $ Return= Array ();
        $ RETURN ['MSG']= '';
        $ Return ['error']= false;
        $ Return ['QueryConent']= '';
        $ Return ['Header']= 'Monoblocks';
        $ Return [CountRecords']= 0;
        Require_ONCE ('config.php');
        $ PDO= NEW PDO ($ DSN, $ User, $ Password);
        //Begin Form Validation Functionality
        if (! isset ($ subcategoryflag) || Empty ($ subcategoryflag)) {
            $ Return ['error']= True;
            $ Return ['MSG'].= '<
Li >
Error: Field1 is empty. ≪
/Li >
';
        }
        //Begin Form Success Functionality
        if (((! $ Return ['error']) &
&
 $ subcategoryflag== 'Monoblocks') {
            $ Return ['MSG']= '<
Div >
≪
DIV Class= "Filtercontainer" >
≪
div class= "filterseogroup filterseogroup__seo" id= "popularcollections" >
≪
H4 Class= "FiltersEogroup__Header" >
Popular selections <
/h4 >
≪
DIV Class= "FiltersEogroup__Group_closed" >
≪
div class= "filterseogroup__item-wrapper" >
≪
a class= "FiltersEogroup__item" href= "https://www.citilink.ru/catalog/monobloki--NEdorogie-Monobloki/" >
Inexpensive <
/a >
≪
/div >
≪
div class= "filterseogroup__item-wrapper" >
≪
a class= "FiltersEogroup__Item" href= "https://www.citilink.ru/catalog/monobloki--dlya-doma-m/" >
For home <
/a >
≪
/div >
≪
div class= "filterseogroup__item-wrapper" >
≪
a class= "filterseogroup__item" href= "https://www.citilink.ru/catalog/monobloki--dlya-ofisa-m/" >
For office <
/a >
≪
/div >
≪
div class= "filterseogroup__item-wrapper" >
≪
a class= "filterseogroup__item" href= "https://www.citilink.ru/catalog/monobloki--win/" >
with windows <
/a >
≪
/div >
≪
div class= "filterseogroup__item-wrapper" >
≪
a class= "filterseogroup__item" href= "https://www.citilink.ru/catalog/monobloki--imac/" >
Apple iMac <
/a >
≪
/div >
≪
/div >
≪
DIV Class= "FiltersEogroup__Toggle-Container" >
≪
Button class= "Filterseogroup__Toggle-Button ButtonStyleDecorator ButtonStyleDecorarator_Theme_GhostOrange ButtonStyleDecorator_Size_S Button" name= "" type= "submit" value= "" tabindex= "0" bordertyle= "none" >
≪
Span class= "Buttonstyledecorator__Text" >
Show all <
/span >
≪
/Button >
≪
/div >
≪
/div >
≪
/div >
≪
/div >
'
        }
            $ SQL= 'SELECT * from monoblocks';
            $ Query= $ PDO->
Prepare ($ SQL);
            $ result= $ Query->
Execute ();
            While ($ example= $ Result->
Fetch (PDO :: Fetch_assoc))
            {
                $ Return ['QueryContent']= '<
Div Style= "Width: 100%; Border: 2px Solid Red >
≪
/div >
';
            };
            $ SQLCountRecords= 'Select Count (*) AS COUNT FROM Monoblocks';
            $ QueryCountrecords= $ PDO->
Prepare ($ sqlcountrecords);
            $ QueryCountRecords->
Execute ();
            $ Return [CountRecords']= $ QuerycountRecords->
fetch (pdo :: fetch_assoc) ['count'];
        //Return Json Encoded Results
        RETURN JSON_ENCODE ($ Return);
    }
}
$ ajaxvalidate= new ajaxvalidate;
Echo $ AjaxValidate->
FormValidate ();
? ≫

As a result, after switching to the Laptop and Computers link -> Monoblocks Instead of displaying the right side menu and the central part error occurs

<
BR />

Fatal Error : Uncaught Error: Call to a Member Function Fetch () on Boolean in C: \ Ospanel \ Domains \ TestSite.ru \ stackoverflowite \ php \ ajaxsubcategory1.php: 48 Stack Trace: # 0 C: \ Ospanel \ domains \ testsite.ru \ stackoverflowite \ php \ ajaxsubcategory1.php (66): Ajaxvalidate-> FORMVALIDATE () # 1 {Main}Thrown In C: \ Ospanel \ Domains \ TestSite.ru \ stackoverflowite \ php \ ajaxsubcategory1.php on line 48

(string While ($ example= $ Result-> Fetch (PDO :: Fetch_assoc)) )

but on https://www.php.net/manual/ru/pdostatement.fetch.php.It is written that the use of fetch in the form $ EXAMPLE= $ Result-> Fetch (PDO :: Fetch_assoc) Permissible

Tell me how to eliminate the use error fetch .

Look carefully in the documentation .... What does the execute return? -It's once ...... And secondly, as an example, see .... Is there a row $ result= $ query->execute (); Or is there still another written?

Алексей Шиманский2021-06-30 04:16:10

@ Alekseyshimansky thank you very much helped.

htmllayout2021-06-29 11:56:30