How to call my css in a php include

Hi,
I have a require_once PHP file in my index.php. The index.php file itself calls another .php file via a href link from a table where it provides the row id to pass to the next page’s stored procedure.
my folder Hierarchy looks like this:

my index.php loads the relevant CSS files but when I check in Chrome using DevTools and Network I can see the files do not load.
How can I include all the CSS in each .php file?

I saw a few explanations but I do not really understand.

You say your index.php loads them, but they do not load. Do you get an error message?

Remember that your destination will also need to include or require the file as well.

If that doesn’t help (which is likely), show us the code for index.php that does load them, and the code in your destination that does not.

Yes sorry, just read my own question and realised it’s not very clear; I have an require_once(‘php/class.php’);
in my html like this:

        <head>

            <meta charset="utf-8">
            <meta http-equiv="x-ua-compatible" content="ie=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">

            <title>Title</title>

            <link rel="manifest" href="site.webmanifest">
            <link rel="apple-touch-icon" href="images/icon.png">

            <link rel="stylesheet" href="styles.css" />
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />


        </head>

        <body>

            <header>
                <img src="images/logo.jpg" />

                <a class="printButton" href="#" onClick="window.print()"><i class="fa fa-2x fa-print printbutton"></i></a>
                <a class="refreshButton" href="#" onClick="window.location.reload();return false;"><i class="fa fa-2x fa-repeat reloadbutton"></i></a>

            </header>

            <!--[if lte IE 9]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser.
              Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
            <![endif]-->

                <div style="overflow-x:auto;">
                        <table class="demo-table">
                                <center>
                                        <h2 class="title"> Title </h2>
                                </center>

                                <?php

                                require_once ( 'php/class.php' );

                                ?>      
                       </table>
                </div>

Then inside the class.php in the last column of each row there is a href link that catches the ‘Id’ of a column to pass to another page with a stored procedure, I call the stored procedure and populate a table. My href:

 href="php/class2.php?id= ' ,

The css, js, images or styles.css are not loading in the class2.php

Do you have the same require_once() in class2.php? Once you get to that code via your href link, everything starts again, it won’t carry anything over from the calling html page.

1 Like

No, the require_once(class.php) is only in my index.php. This class doesn’t have any includes in it because all styles load. class.php is only the class to connect to the DB and call the SP, class2 is another connection to the DB calling another SP.
When I tried to put an include or require in my class2.php the page won’t load at all.

That seems strange, would need to see the code to comment.

But if you don’t include the file that links to all the CSS and so on, it’s no surprise that it doesn’t display. Once you are at the target of your href, that’s a new page for your browser. You have to specify everything you want on it.

1 Like

Thanks for your help, I realise what I need to do; my code isn’t very clean and I an not using my classes correctly. I am creating and populating each table inside my class and only including the name of the class in my index.php.
I tested by wrapping my class.php with HTML and all pages loaded the styles required, then I realised that if I use my classes to connect to the DB and SP but call the populating tables with POST in my index.PHP, everything works as it should without repeating code.
A very important lesson for me there, thanks for all help provided,

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.