0

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?

Edited by Squidge

2
Contributors
5
Replies
9
Views
5 Years
Discussion Span
Last Post by Squidge
0

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'?

2

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";
}

Edited by broj1

0

@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

0

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?

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.