I am ever so close to resolving the issue I have with taking some data from my tables, basically I have a users tables, a category tables and a join tables which has foreign keys assigned to the user_id from the users table and the cat_id taken from the cats table.
I basically want to show different categories if they have been assigned to you and in my database in the join table I can select a user id and cat id and that has its own id in a row. the trouble i face is getting those categories to show against the users id when logged in?
Here is my code so far:
<?php
require ('../db_con.php');
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    // BUILD AND DISPLAY THE CATEGORY LIST (RICOH BUILD)
    function build_cat_list()
    {
    global $dbc;
    $user = $_SESSION['user'];
    $q = sprintf("
        SELECT
           count(*)
        FROM
            cats
        INNER JOIN
            user_cat_join
        ON
            cats.cat_id = user_cat_join.cat_id
        WHERE
            user_cat_join.user_id = '%s'
        ",
        mysqli_real_escape_string($dbc, $user)
    );
    $r = mysqli_query ($dbc, $q); // Run the query.
    // FETCH AND PRINT ALL THE RECORDS
    while ($row = mysqli_fetch_array($r)) {
    echo '
    <a href="view_cat.php?cat_id='.$row["cat_id"].'">
        <div class="indexBox"">
            <div class="indexBoxHeader"  style="background-color:'.$row["cat_color"].'"><p>'
                .$row["cat_icon"].'</p>
                </div>
            <div class="indexBoxFooter">
                <p>'.$row["cat_name"].'</p>
            </div>
        </div>
    </a>';
    }
}
?>
As it stand, it is running through the entire script because what it does it builds a little box with an icon, a background color and a name printed on the box. But at the moment it renders the box but tells me there are some undefined variables which I know what the error means but struggling to overcome it?
Notice: Undefined index: cat_id in C:\MAMP\htdocs\functions\functions.inc.php on line 36
Notice: Undefined index: cat_color in C:\MAMP\htdocs\functions\functions.inc.php on line 38
Notice: Undefined index: cat_icon in C:\MAMP\htdocs\functions\functions.inc.php on line 39
Notice: Undefined index: cat_name in C:\MAMP\htdocs\functions\functions.inc.php on line 42
And of course the above variables are referring to the bottom part where it actually renders out the box. It will only show me these undefined variables if I use count(*) but if I specify them like cat_name, cat_color etc etc I get nothing and no errors?
 
     
    