donglan6967 2009-09-07 19:47
浏览 26
已采纳

Dreamweaver Recordset默认值(PHP) - 如何返回所有记录?

Greetings! Although I am working in Dreamweaver, this question may be general enough for PHP/MySQL experts to comment on.

$colname_get_voice_search_men = "-1";
if (isset($_POST['search_type'])) {
  $colname_get_voice_search_men = $_POST['search_type'];
}
mysql_select_db($database_conn_talent, $conn_talent);
$query_get_voice_search_men = sprintf("SELECT * FROM view_voice_search_men WHERE voice_type_id = %s", GetSQLValueString($colname_get_voice_search_men, "int"));
$get_voice_search_men = mysql_query($query_get_voice_search_men, $conn_talent) or die(mysql_error());
$row_get_voice_search_men = mysql_fetch_assoc($get_voice_search_men);
$totalRows_get_voice_search_men = mysql_num_rows($get_voice_search_men);

Dreamweaver sets the default value to "-1" to ensure no records are returned by default. However, I want all records to be returned by default. So, I naturally changed

$colname_get_voice_search_men = "-1"

to

$colname_get_voice_search_men != "-1"

But this doesn't change the results, which is no records are returned. I've also tried > "0" but no joy.

Your feedback is greatly appreciated.

Thanks.

  • 写回答

1条回答 默认 最新

  • douxin8610 2009-09-10 15:33
    关注

    Probably the easiest way to accomplish your goal would be to wrap the recordset code with an if statement that checks to see if $colname_get_voice_search_men is not equal to -1 (you are supplied a "search_type" and therefore should limit the results) and then in an else branch copy the recordset code but remove the WHERE clause and the variable replacement so that you can get all of the results.

    Something like the following:

    $colname_get_voice_search_men = "-1";
    if (isset($_POST['search_type'])) {
      $colname_get_voice_search_men = $_POST['search_type'];
    }
    
    if($colname_get_voice_search_men != -1){ // search_type specified
    mysql_select_db($database_conn_talent, $conn_talent);
    $query_get_voice_search_men = sprintf("SELECT * FROM view_voice_search_men WHERE voice_type_id = %s", GetSQLValueString($colname_get_voice_search_men, "int"));
    $get_voice_search_men = mysql_query($query_get_voice_search_men, $conn_talent) or die(mysql_error());
    $row_get_voice_search_men = mysql_fetch_assoc($get_voice_search_men);
    $totalRows_get_voice_search_men = mysql_num_rows($get_voice_search_men);
    }
    else{ // return all
    mysql_select_db($database_conn_talent, $conn_talent);
    $query_get_voice_search_men = "SELECT * FROM view_voice_search_men";
    $get_voice_search_men = mysql_query($query_get_voice_search_men, $conn_talent) or die(mysql_error());
    $row_get_voice_search_men = mysql_fetch_assoc($get_voice_search_men);
    $totalRows_get_voice_search_men = mysql_num_rows($get_voice_search_men);
    }
    

    If you weren't using Dreamweaver, I'd probably put the if statement around the line creating the SQL statement ( $query_get_voice_search_men = sprintf(....) ) , but Dreamweaver will often not recognize recordsets when you modify the code it generates. As it is, the edits I'm suggesting may cause Dreamweaver to not "see" your recordset.

    So if you no longer see your recordset in the Server Behaviors panel, or entries in the Bindings panel, then Dreamweaver isn't properly recognizing the recordset code. If that is the case, then my suggestion is to build out the page using the original recordset code (and the associated repeating regions and items from the binding panel), and once you're "done" with the page, add in the conditional code. That will allow you to make the most of Dreamweaver's recordset tooling before you add in the "return all" code.

    One note: I'm assuming that your return all branch doesn't return a huge number of records. If it does, then you should probably add a LIMIT clause to the SQL so that you only get say the top 1000 or so. Check out the MySQL docs for a SELECT statement, which includes some discussion of LIMIT.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题