While Loop Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jesse Burns aka jburns131

    #1

    While Loop Problem

    I've got a coding problem here that I could use some help with.

    Here's my db class (the config.php only has db connection info):

    *************** *************** *************** *************** ********

    <?php

    // db_handler.inc

    require_once("c onfig.php");

    class db {

    var $mySQLresult;

    function db() {

    $this->dbConn = mysql_connect(D B_HOST, DB_USER, DB_PW);
    mysql_select_db (DB_NAME, $this -dbConn) or
    die(mysql_error ());
    }

    function db_Select($tabl es, $columns="'*'", $conditions="") {

    $sql = "SELECT ".$columns. " FROM ".$tables." ".$conditio ns;
    $row = mysql_query($sq l, $this -dbConn) or
    die(mysql_error ());
    $this->mySQLresult = $row;
    }

    function db_Fetch($type = MYSQL_BOTH) { //MYSQL_ASSOC
    $row = mysql_fetch_arr ay($this -mySQLresult, $type) or
    die(mysql_error ());
    if ($row) {
    return $row;
    } else {
    return FALSE;
    }
    }
    }

    ?>

    *************** *************** *************** *************** ********

    Here's the code I'm executing:

    *************** *************** *************** *************** ********

    <?php

    require_once("i ncludes/db_handler.inc" );
    require_once("i ncludes/config.php");

    echo "Hit 1<br />";

    $sql = new db;
    $result = $sql -db_Select(DB_TA BLE_ORG_INFO);
    while ($row = $sql -db_Fetch()) {

    $organization_d isclaimer =
    $row['organization_d isclaimer'];
    }

    echo "Hit 2<br />";

    ?>

    *************** *************** *************** *************** ********

    For some reason, the while loop is halting execution and won't display
    "echo "Hit 2<br />";". The script just stops executing.

    Any idea's why?

    I'm using php5
  • Rik Wasmus

    #2
    Re: While Loop Problem

    On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
    <jburns131@gmai l.comwrote:
    I've got a coding problem here that I could use some help with.
    $row = mysql_fetch_arr ay($this -mySQLresult, $type) or
    die(mysql_error ());
    Don't use 'or die()' here. If there are no further results (rows are
    finished), mysql_fetch_arr ay() will return false, the die() will be
    executed, with nothing to display as there is no mysql_error(), it's just
    worked correctly.

    And don't die() in production. Log the error, and degrade as gracefull as
    you can.
    --
    Rik Wasmus

    Comment

    • Jesse Burns aka jburns131

      #3
      Re: While Loop Problem


      Sorry for the delay in response, I've had trouble with my connection.

      That was my problem. Thank you very much for the help and advise.

      I hope you and everyone else had a great holiday.


      "Rik Wasmus" <luiheidsgoeroe @hotmail.comwro te in message
      news:op.t14z8k1 c5bnjuv@metalli um.lan...
      On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
      <jburns131@gmai l.comwrote:
      I've got a coding problem here that I could use some help with.
      $row = mysql_fetch_arr ay($this -mySQLresult, $type) or
      die(mysql_error ());
      Don't use 'or die()' here. If there are no further results (rows are
      finished), mysql_fetch_arr ay() will return false, the die() will be
      executed, with nothing to display as there is no mysql_error(), it's just
      worked correctly.

      And don't die() in production. Log the error, and degrade as gracefull as
      you can.
      --
      Rik Wasmus


      Comment

      • Rik Wasmus

        #4
        Re: While Loop Problem

        "Rik Wasmus" <luiheidsgoeroe @hotmail.comwro te in message
        news:op.t14z8k1 c5bnjuv@metalli um.lan...
        On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
        <jburns131@gmai l.comwrote:
        >I've got a coding problem here that I could use some help with.
        >
        > $row = mysql_fetch_arr ay($this -mySQLresult, $type) or
        >die(mysql_erro r());
        >
        Don't use 'or die()' here. If there are no further results (rows are
        finished), mysql_fetch_arr ay() will return false, the die() will be
        executed, with nothing to display as there is no mysql_error(), it's just
        worked correctly.
        >
        And don't die() in production. Log the error, and degrade as gracefullas
        you can.
        On Sat, 24 Nov 2007 20:32:13 +0100, Jesse Burns aka jburns131
        <jburns131@jbwe bware.comwrote:
        Sorry for the delay in response, I've had trouble with my connection.
        >
        That was my problem. Thank you very much for the help and advise.
        >
        I hope you and everyone else had a great holiday.
        You're welcome, there was no holiday in The Netherlands I'm aware off,
        however, I'll finally have 1 week of in 2 weeks, and I'll make the most of
        it :)
        --
        Rik Wasmus

        Comment

        Working...