PHP/MySQL Problem

Posted by Scott on Stack Overflow See other posts from Stack Overflow or by Scott
Published on 2010-05-07T18:52:00Z Indexed on 2010/05/07 18:58 UTC
Read the original article Hit count: 150

Filed under:
|

Why does this only print the sites specific content under the first site, and doesn't do it for the other 2?

<?php
        echo 'NPSIN Data will be here soon!';

        // connect to DB
        $dbhost = 'localhost';
        $dbuser = 'root';
        $dbpass = 'root';

        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to DB');

        $dbname = 'npsin';

        mysql_select_db($dbname);

        // get number of sites
        $query = 'select count(*) from sites';
        $result = mysql_query($query) or die ('Query failed: ' . mysql_error());

        $resultArray = mysql_fetch_array($result);
        $numSites = $resultArray[0];

        echo "<br><br>";

        // get all sites
        $query = 'select site_name from sites';
        $result = mysql_query($query);

        // get site content
        $query2 = 'select content_name, site_id from content';
        $result2 = mysql_query($query2);

        // get site files


        // print info
        $count = 1;
        while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
                echo "Site $count: ";
                echo "$row[0]";
                echo "<br>";
                $contentCount = 1;
                while ($row2 = mysql_fetch_array($result2, MYSQL_NUM)) {
                        $id = $row2[1];
                        if ($id == ($count - 1)) {
                                echo "Content $contentCount: ";
                                echo "$row2[0]";
                                echo "<br>";
                        }

                        $contentCount++;
                }

                $count++;
        }
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql