Hi all,

Hoping you can assist. I am probably starring at the darn thing but i cannot see the wood through the trees :)

class headScript
{
    public function connection()
    {
        try
        {
            $dbh = new PDO("mysql:host=localhost;dbname=xxx", 'xxx', 'xxx'); // Dev         
            return $dbh;
        }
        catch(PDOException $e)
        {
            echo "Error :- " . $e->getMessage();
            die();
        }
    }   


    public function headLoad()
    {

        $cxn = $this->connection()->prepare("SELECT scriptCode FROM head_scrips WHERE active = '0'");

        $cxn->execute();
        $cxn->setFetchMode(PDO::FETCH_ASSOC);

        print "<script>";
        while($row = $cxn->fetch())
        {
            print $row['scriptCode'];
        }
        print "</script>";

    }


}

I have this basic class, it will get all active scripts from the database.

I am using this to relay hte data to the page head:

$scriptOut = new headScript;
print $scriptOut->headLoad();

I am getting the <script> tags rendered but no script

Can you assist?

Recommended Answers

All 5 Replies

Just a dumb question: if you want to get active scripts why is the condition WHERE active = '0'? Shouldn't it be WHERE active != '0'?

Or put a counter within a while loop and see how many rows you get (you might use PDO's number of rows function):

public function headLoad()
{

    // debug ceounter
    $i = 0;

    $cxn = $this->connection()->prepare("SELECT scriptCode FROM head_scrips WHERE active = '0'");
    $cxn->execute();
    $cxn->setFetchMode(PDO::FETCH_ASSOC);
    print "<script>";
    while($row = $cxn->fetch())
    {
        print $row['scriptCode'];

        // increase the counter
        $i++;
    }
    print "</script>";

    // print the counter
    echo "Number of rows: $i";
}

@broj1,

Sorry was a typo :(

It is as you have put where active != 0 in my script.

Just cant figure out why it is not showing the damn thing

Have you tried to count the actual records that the query returns as I suggested in my next post? Or have you tried to test the query in phpmyadmin?

Have you tried to count the actual records that the query returns as I suggested in my next post? Or have you tried to test the query in phpmyadmin?

:) i had a darn typo in my table name!!! @broj1 thanks for your assistance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.