How to Build a CSS With MySQL and PHP

When you want to allow users to customize their themes, you must store the CSS information in your website's MySQL database. When the page renders in the user's browser, the CSS queries from the database server and the PHP code prints the CSS code to your Web page. You must make a connection to the server, query the CSS database and use the PHP "echo" statement to print the results to your Web page.

Instructions

    • 1

      Right-click the PHP file you want to use to display the CSS code. Click "Open With," and then click your preferred PHP editor.

    • 2

      Create the query for the CSS retrieval. The query syntax depends on the table in which you store the CSS code. The following code is an example of how you query a MySQL table:

      $query = "select csscode from css where userpreference=2";

    • 3

      Get the CSS code from the database. The following code queries the server and stores the result in the "css" variable:

      $css = mysql_query($query);

    • 4

      Display the code on your page. The following code implements the CSS on your Web page:

      <script type="text/css">

      <?php

      echo $css;

      ?>

      </script>

Related Searches:

References

Comments

Related Ads

Featured