We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

My brain has given up......

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?

2
Contributors
5
Replies
19 Hours
Discussion Span
8 Months Ago
Last Updated
8
Views
Question
Answered
Squidge
Posting Pro in Training
406 posts since Dec 2009
Reputation Points: 111
Solved Threads: 60
Skill Endorsements: 5

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

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

@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

Squidge
Posting Pro in Training
406 posts since Dec 2009
Reputation Points: 111
Solved Threads: 60
Skill Endorsements: 5

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?

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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.

Squidge
Posting Pro in Training
406 posts since Dec 2009
Reputation Points: 111
Solved Threads: 60
Skill Endorsements: 5
Question Answered as of 8 Months Ago by broj1

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0731 seconds using 2.72MB