473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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("config.php");

class db {

var $mySQLresult;

function db() {

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

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

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

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

?>

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

Here's the code I'm executing:

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

<?php

require_once("includes/db_handler.inc");
require_once("includes/config.php");

echo "Hit 1<br />";

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

$organization_disclaimer =
$row['organization_disclaimer'];
}

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
Nov 21 '07 #1
3 1358
On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
<jb*******@gmail.comwrote:
I've got a coding problem here that I could use some help with.
$row = mysql_fetch_array($this -mySQLresult, $type) or
die(mysql_error());
Don't use 'or die()' here. If there are no further results (rows are
finished), mysql_fetch_array() 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
Nov 21 '07 #2

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" <lu************@hotmail.comwrote in message
news:op***************@metallium.lan...
On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
<jb*******@gmail.comwrote:
I've got a coding problem here that I could use some help with.
$row = mysql_fetch_array($this -mySQLresult, $type) or
die(mysql_error());
Don't use 'or die()' here. If there are no further results (rows are
finished), mysql_fetch_array() 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
Nov 24 '07 #3
"Rik Wasmus" <lu************@hotmail.comwrote in message
news:op***************@metallium.lan...
On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
<jb*******@gmail.comwrote:
>I've got a coding problem here that I could use some help with.
> $row = mysql_fetch_array($this -mySQLresult, $type) or
die(mysql_error());

Don't use 'or die()' here. If there are no further results (rows are
finished), mysql_fetch_array() 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
<jb*******@jbwebware.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
Nov 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bluexcell | last post by:
While: This repeatedly tests the expression and, if it is true, executes the first suite; if the expression is false (which may be the first time it is tested) the suite of the else clause, if...
9
by: Ben | last post by:
I have two 'Do While Not' statements, that are getting information from the same recordset. If I comment out the first one I can get the results for the second one, and vice-versa. Why is this...
147
by: Michael B Allen | last post by:
Should there be any preference between the following logically equivalent statements? while (1) { vs. for ( ;; ) { I suspect the answer is "no" but I'd like to know what the consensus is
12
by: Howard | last post by:
Hello everyone (total VB.NET beginner here), I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came across an exercise that I can't get to work. The exercise asks that you create...
7
by: DaVinci | last post by:
I am writing a pong game.but met some problem. the ball function to control the scrolling ball, void ball(int starty,int startx) { int di ,i; int dj,j; di = 1; dj = 1; i = starty;
1
by: pauljturner99 | last post by:
Hi, I'm trying to pass a parameter from a for loop to the nested while loop but only the first counter is passed. Here is the code: dim ctr redim ctr(5) ctr(0) = 2 ctr(1) = 4 ctr(2) = 6
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
2
by: d3vkit | last post by:
Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies. I am using PHP5 with...
7
by: Problematic coder | last post by:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing Dim objcnn As Data.OracleClient.OracleConnection = Nothing Dim objcom As Data.OracleClient.OracleCommand objcom = New...
5
by: =?Utf-8?B?V2lsbGlhbSBGb3N0ZXI=?= | last post by:
Good evening all, I am trying to write a process that uses a while loop to cycle multiple files from an array throught the StreamReader Process. The whole thing works using: Dim...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.