CliffLandin
Programmer
I am trying to gather information from a dbase, displaying it as I go. The script works fine except the first field that matches the criteria isn't read or displayed.
For example:
On this page I check to see if a session variable 'tripNumb' is set. If it isn't, it goes to the dbase and gets the last trip number and adds one to it. The problem is that if there is only one field in the dbase it doesn't read it.
This is how I am reading the fields:
{
$link = mysql_connect(*,*,*);
if (!$link) {
die("Could not connect: " . mysql_error());
}
mysql_select_db(*, $link)
or die("Could not select database");
$query = "SELECT nID, tripNO FROM reqsTL";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
while ($row = mysql_fetch_row($result)){
$nID=$row[0];
$tripNO=$row[1];
}
mysql_close($link);
$tripNO++;
$_SESSION['tripNum']=$tripNO;
}
If there was one field in the dbase and the trip number for that field is 150 the query above would return 0 and add 1 to it. If there were two fields in the dbase and the trip number for the second field was 151 the query above would return 151 and add 1 to it so $tripNO and $_SESSION['tripNum'] would be 152.
This occurs in a couple of different spots in the page. In fact, whereever I use the while ($row = mysql_fetch_row($result)).
What am I doing wrong? It is really infuriating.
Thanks for any help that anyone can offer.
When in doubt, go flat out!
For example:
On this page I check to see if a session variable 'tripNumb' is set. If it isn't, it goes to the dbase and gets the last trip number and adds one to it. The problem is that if there is only one field in the dbase it doesn't read it.
This is how I am reading the fields:
{
$link = mysql_connect(*,*,*);
if (!$link) {
die("Could not connect: " . mysql_error());
}
mysql_select_db(*, $link)
or die("Could not select database");
$query = "SELECT nID, tripNO FROM reqsTL";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
while ($row = mysql_fetch_row($result)){
$nID=$row[0];
$tripNO=$row[1];
}
mysql_close($link);
$tripNO++;
$_SESSION['tripNum']=$tripNO;
}
If there was one field in the dbase and the trip number for that field is 150 the query above would return 0 and add 1 to it. If there were two fields in the dbase and the trip number for the second field was 151 the query above would return 151 and add 1 to it so $tripNO and $_SESSION['tripNum'] would be 152.
This occurs in a couple of different spots in the page. In fact, whereever I use the while ($row = mysql_fetch_row($result)).
What am I doing wrong? It is really infuriating.
Thanks for any help that anyone can offer.
When in doubt, go flat out!