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 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳