Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php exeptions? 1

Status
Not open for further replies.

GroundZero

Programmer
Feb 1, 2001
28
0
0
CA
Hi everyone I am trying to understand something that php's been doing to me for 3 days now and I was hoping someone could tell me what's happening.

here is the problem:

I am using nested while loops but the first one need a semicolon (;) to work and the second one won't work if I put one (seem to be going in an infinite loop)and won't work if I don't put it any idea why sometime I have to put the semicolon(;) and sometime I don't? I have never used a loop with it at the end and it was working.

also could you tell me what is wrong in my script loops?

//connect to database
$connect = odbc_connect("$DBname", "", "") or die("couldn't connect.");

//query the user table for room and message
$query = "SELECT $DBselect FROM $DBtable";

if ($DBwhere!="none")
{
$query .= "WHERE $DBwhere=$DBfield";
}

//perform the query
$result = odbc_do($connect, $query);

$NbFields=odbc_num_fields($result);
$NbRows=odbc_num_rows($result);
$i=1;
$j=1;

while($i<=$NbRows);
{
odbc_fetch_row($result,$i);
while ($j <=$NbFields)
{
$A=odbc_field_name($result,$j);
$B=urlencode(odbc_result($result,$j));
print(&quot;$A$i=$B&&quot;);
$j++;
}
$i++;
}



print(&quot;ok=1&&quot;);
print(&quot;maxi=$i&&quot;);

//disconnect from database
odbc_close($connect);

break;

I send the needed var with the url box of the browser:

?DBname=rompDB1&DBselect=all&DBwhere=none&DBtable=User

thank you in advance,

GroundZero Your soul is imperfect
Life is difficult...

Now guess why we're here
 
Hi GroundZero -- I checked out your code and this is all I could find. Your code:

while($i<=$NbRows);
{
odbc_fetch_row($result,$i);
while ($j <=$NbFields)
{
$A=odbc_field_name($result,$j);
$B=urlencode(odbc_result($result,$j));
print(&quot;$A$i=$B&&quot;);
$j++;
}
$i++;
}


it should be:
while($i<=$NbRows)
{
odbc_fetch_row($result,$i);
while ($j <=$NbFields)
{
$A=odbc_field_name($result,$j);
$B=urlencode(odbc_result($result,$j));
print(&quot;$A$i=$B&&quot;);
$j++;
}
$i++;
}

That's how while loops work if you are still caught in a infinite loop you might want to try moving the i++ to above the second while loop below the odbc_fetch_row($result,$i);.

Hope that helps.

WebProgrammerGoddess
 
thank you WebProgrammerGoddess but I ,finnaly found out what the mistake is!

it is the odbc_num_rows that didn't work because there is a problem with many odbc drivers so I now need a way to find out how to do this function another way but I think I'll be able to do so without much trouble.

regards,

GroundZero Your soul is imperfect
Life is difficult...

Now guess why we're here
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top