Thank You. This did the trick. I knew that it had to be something simple. I wasn't even thinking of a "if(!$row)" statement.
Steve At 10:05 AM 3/14/2002, you wrote: >----- Original Message ----- >From: "Steve Buehler" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Thursday, 14 March, 2002 17:46 >Subject: Checking if table empty > > >: I have a strange, but probably easy to fix problem. I need to check to >see >: if something is in a table...that part is easy, but if the table is empty, >: it doesn't go through my "while" statement so that I can create something >: in it. I am sure that if there was something in the table, that I would >: not be having this problem. Below is my code. >: >: ----------- >: $searchStmt = "SELECT * from division1rank"; >: >: $stmt= substr($searchStmt, 0, strlen($searchStmt)) ; >: >: // Connect to the Database >: if (!($link=mysql_pconnect($hostName, $userName, $password))) { >: DisplayErrMsg(sprintf("error connecting to host %s, by user %s", >: $hostName, $userName)) ; >: exit() ; >: } >: >: // Select the Database >: if (!mysql_select_db($databaseName, $link)) { >: DisplayErrMsg(sprintf("Error in selecting %s database", $databaseName)) >; >: DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), >: mysql_error($link))) ; >: exit() ; >: } >: >: // Execute the Statement >: if (!($result =mysql_query($stmt, $link))) { >: DisplayErrMsg(sprintf("Error in executing %s stmt", $stmt)) ; >: DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), >: mysql_error($link))) ; >: exit() ; >: } >: > >substitute "while (($row = mysql_fetch_object($result))){" with this here: >-------cut------ > $row = mysql_fetch_object($result); > if (! $row) { > // table empty > } > while ($row) { > >-------cut------ > > >: if($row->team_id == "$team_id"){ >: echo "It is in there"; >: }else{ >: echo "We will need to add it to the table"; >: } > >and add this here: >-------cut------ > $row = mysql_fetch_object($result); >-------cut------ > >: } >: } >: >: >: --------------------------------------------------------------------- >: Before posting, please check: >: http://www.mysql.com/manual.php (the manual) >: http://lists.mysql.com/ (the list archive) >: >: To request this thread, e-mail <[EMAIL PROTECTED]> >: To unsubscribe, e-mail ><[EMAIL PROTECTED]> >: Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php >: --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php