Jump to content

[SOLVED] PHP Newb needs help coverting from ASP


billerda

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.