billerda Posted September 17, 2007 Share Posted September 17, 2007 Hi All, I'm doing my first php/mysql web site and I'm stuck on something that would be a cakewalk in ASP. Please help me to get my brain around this. In ASP, the syntax I'm looking would be "Do while NOT rs.eof(). ??? All I want to do with my open my recordset is... 1. While there are records, print them. 2. If there are no results, print "No results found". The below code I am using works except that in the first case, it prints all the records found in the db and then ALSO prints the line "No results found" at EOF. I need to get rid of that last line. Thanks in advance for your help! Bill ************** CODE ********************** <?php // Request and store the specialty and region variables from the form. // $strSpecialty = $_POST['ddSpecialty']; $strRegion = $_POST['ddRegion']; // Make the SQL query to the database. // $result = mysql_query("SELECT ID, CompanyName, Address1, Address2, City, State, ZipCode, Telephone, Fax, Email, WebSite, Description FROM tblRegistrants WHERE SpecID = $strSpecialty AND RegID = $strRegion"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } // Display the lawyers found in the database that match the search criteria. // while ( $row = mysql_fetch_array($result) ) { echo("<li><b>" . $row["CompanyName"] . "</b> · "); echo($row["City"] . ", " . $row["State"] . " "); echo("[<a href=\"find_attorney_bio.php?ID= . $row["ID] . "\"> View Bio </a>]</li>"); } if (!$row = mysql_fetch_array($result)) { echo("<span class='redText'>* We're sorry, no results were found based on the criteria you've selected.</span>"); } ?> ************** MY CURRENT RESULTS ********************** * Paul D. Bradford PLLC · Raleigh, NC [ View Bio ] * Jeffrey E. Marshall, Attorney at Law · Raleigh, NC [ View Bio ] * Donald A. Davis Attorney at Law · Raleigh, NC [ View Bio ] * Brewer & Wright · Raleigh, NC [ View Bio ] * Orcutt Law Offices · Raleigh, NC [ View Bio ] * We're sorry, no results were found based on the criteria you've selected. Thanks Again Link to comment https://forums.phpfreaks.com/topic/69633-solved-php-newb-needs-help-coverting-from-asp/ Share on other sites More sharing options...
billerda Posted September 17, 2007 Author Share Posted September 17, 2007 Solved it with a solutiong from another site. Thanks. $sqltext= "SELECT ID, CompanyName, Address1, Address2, City, State, ZipCode, Telephone, Fax, Email, WebSite, Description FROM tblRegistrants WHERE SpecID = $strSpecialty AND RegID = $strRegion"; $result = mysql_query($sqltext); if(mysql_num_rows($result)>0){ while ( $row = mysql_fetch_array($result) ) { echo("<li><b>" . $row["CompanyName"] . "</b> · "); echo($row["City"] . ", " . $row["State"] . " "); echo("[<a href=\"find_attorney_bio.php?ID= . $row["ID] . "\"> View Bio </a>]</li>"); } }else{ echo("<span class='redText'>* We're sorry, no results were found based on the criteria you've selected.</span>"); } Link to comment https://forums.phpfreaks.com/topic/69633-solved-php-newb-needs-help-coverting-from-asp/#findComment-349904 Share on other sites More sharing options...
ViN86 Posted September 17, 2007 Share Posted September 17, 2007 Solved it with a solutiong from another site. Thanks. $sqltext= "SELECT ID, CompanyName, Address1, Address2, City, State, ZipCode, Telephone, Fax, Email, WebSite, Description FROM tblRegistrants WHERE SpecID = $strSpecialty AND RegID = $strRegion"; $result = mysql_query($sqltext); if(mysql_num_rows($result)>0){ while ( $row = mysql_fetch_array($result) ) { echo("<li><b>" . $row["CompanyName"] . "</b> · "); echo($row["City"] . ", " . $row["State"] . " "); echo("[<a href=\"find_attorney_bio.php?ID= . $row["ID] . "\"> View Bio </a>]</li>"); } }else{ echo("<span class='redText'>* We're sorry, no results were found based on the criteria you've selected.</span>"); } i was just about to tell you to use mysql_num_rows to check for a result Link to comment https://forums.phpfreaks.com/topic/69633-solved-php-newb-needs-help-coverting-from-asp/#findComment-349932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.