开发者

Retrieving records within a PHP function

开发者 https://www.devze.com 2023-03-01 15:11 出处:网络
The following code is taken from a perfect working drop down list, and then when I put it into a function it breaks it! Am I doing something wrong here?

The following code is taken from a perfect working drop down list, and then when I put it into a function it breaks it! Am I doing something wrong here?

<?php

require "conne开发者_C百科ct.php";
//create country lists

function records() {
  $countryOptions = '';
  $query = "SELECT DISTINCT country FROM regions";
  $result = mysql_query($query);
  if (!$result) {
    $countryOptions = "<option>Error Retrieving Records</option>\n";;
    }
  else {
    while ($row=mysql_fetch_assoc($result)) {
      $countryOptions .= "<option value=\"{$row['country']}\">";
      $countryOptions .= "{$row['country']}";
      $countryOptions .= "</option>\n";
      }
    }
  }

echo records();

?>


You're not outputting $countryOptions anywhere.

Either add

echo $countryOptions;

at the end of the function or better yet use

return $countryOptions;

and call the function like this:

echo records();

(or implement it to fit your exact needs - it's hard to tell how you use it in your own code)

0

精彩评论

暂无评论...
验证码 换一张
取 消