資料查詢後,秀出的問題!

edited 十月 2013 in PHP新手區
請問喔!我現在資料庫存在資料查詢後會秀出來!但如果是沒有存在的資料我要他秀出!"您所輸入的資料不正確"那我要如何做啊!

<?


//
[ 基本設定 ]
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "cust";
//

//準備好您的 SQL 語法(查詢)
$sql = "SELECT cust_id, cust_id2, LICENSE FROM cust WHERE cust_id = '" .$cust_id. "'";

$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
$result=mysql_db_query( $mysql_database, $sql,$conn );
while($row=mysql_fetch_row($result))
{
//print_r($row);
?>
<style type="text/css">
<!--
body {
background-color: #66FFCC;
}
.style4 {
font-size: 24px;
font-weight: bold;
}
-->
</style>

<table width="355" border="1" align="center" bordercolor="#E0DFE3" bgcolor="#CCFFFF">
<tr>
<td width="81">卡號:</td>
<td width="258"><?=$row[0]?></td>
</tr>
<tr>
<td>廠商編號:</td>
<td><?=$row[1]?></td>
</tr>
<tr>
<td>車號:</td>
<td><?=$row[2]?></td>
</tr>
</table>

<?
echo "<p>";
}
mysql_free_result($result);


?>

<p align="center" class="style4"><a href="/cust.htm">回首頁從新查詢</a></p>

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=1485

評論

  • edited 四月 2006
    提示 => mysql_num_rows()
  • edited 四月 2006
    管理員先生!我改出來了!您給我的提示,這樣用對嗎?
    還是管理員先生有更棒的辨法!
    <?


    //
    [ 基本設定 ]
    $mysql_server_name = "localhost";
    $mysql_username = "root";
    $mysql_password = "702136";
    $mysql_database = "cust";
    //

    //準備好您的 SQL 語法(查詢)
    $sql = "SELECT cust_id, cust_id2, LICENSE FROM cust WHERE LICENSE = '" .$LICENSE. "'";

    $conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
    $result=mysql_db_query( $mysql_database, $sql,$conn );
    if (mysql_num_rows($result)=="0")
    {
    echo mysql_num_rows($result);
    // header("Location:test1.php");

    }
    else
    {

    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title>無標題文件</title>
    <style type="text/css">
    <!--
    body {
    background-color: #009966;
    }
    .style2 {color: #FFFFFF}
    -->
    </style>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_reloadPage(init) { //reloads the window if Nav4 resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);

    function MM_timelinePlay(tmLnName, myID) { //v1.2
    //Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Macromedia, Inc. All rights reserved.
    var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,propNum,theObj,firstTime=false;
    if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
    tmLn = document.MM_Time[tmLnName];
    if (myID == null) { myID = ++tmLn.ID; firstTime=true;}//if new call, incr ID
    if (myID == tmLn.ID) { //if Im newest
    setTimeout('MM_timelinePlay("'+tmLnName+'",'+myID+')',tmLn.delay);
    fNew = ++tmLn.curFrame;
    for (i=0; i<tmLn.length; i++) {
    sprite = tmLn;
    if (sprite.charAt(0) == 's') {
    if (sprite.obj) {
    numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
    if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr-1]) {//in range
    keyFrm=1;
    for (j=0; j<sprite.values.length; j++) {
    props = sprite.values[j];
    if (numKeyFr != props.length) {
    if (props.prop2 == null) sprite.obj[props.prop] = props[fNew-firstKeyFr];
    else sprite.obj[props.prop2][props.prop] = props[fNew-firstKeyFr];
    } else {
    while (keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]) keyFrm++;
    if (firstTime || fNew==sprite.keyFrames[keyFrm-1]) {
    if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm-1];
    else sprite.obj[props.prop2][props.prop] = props[keyFrm-1];
    } } } } }
    } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
    if (fNew > tmLn.lastFrame) tmLn.ID = 0;
    } }
    }

    function MM_initTimelines() { //v4.0
    //MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.
    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    document.MM_Time = new Array(1);
    document.MM_Time[0] = new Array(0);
    document.MM_Time["Timeline1"] = document.MM_Time[0];
    document.MM_Time[0].MM_Name = "Timeline1";
    document.MM_Time[0].fps = 15;
    document.MM_Time[0].lastFrame = 0;
    for (i=0; i<document.MM_Time.length; i++) {
    document.MM_Time.ID = null;
    document.MM_Time.curFrame = 0;
    document.MM_Time.delay = 1000/document.MM_Time.fps;
    }
    }
    //-->
    </script>
    </head>

    <body onLoad="MM_timelinePlay('Timeline1')"VLink="#CC00FF" ALink="#006666">
    <p> </p>
    <p align="center"> </p>
    <p align="center"><img src="/5.jpg" width="720" height="120" align="middle"></p>
    <form name="form3" method="post" action="">
    <table width="810" border="0" align="center" bordercolor="#666666" bgcolor="#666666">
    <tr>
    <td width="334"> </td>
    <td width="100"><span class="style2"><a href="/Maintain.htm">線上叫修</a></span></td>
    <td width="117"><span class="style2"><a href="/cust.htm">資料查詢</a></span></td>
    <td width="117"><span class="style2">營業項目</span></td>
    <td width="120"><span class="style2">聯絡我們</span></td>
    </tr>
    </table>
    </form>
    <p align="center"> </p>
    <?

    while($row=mysql_fetch_row($result))
    {
    //print_r($row);

    ?>

    <form name="form1" method="post" action="">
    <table width="355" border="1" align="center" bordercolor="#E0DFE3" bgcolor="#00FFFF">
    <tr>
    <td width="81">卡號:</td>
    <td width="258"><?=$row[0]?></td>
    </tr>
    <tr>
    <td>廠商編號:</td>
    <td><?=$row[1]?></td>
    </tr>
    <tr>
    <td>車號:</td>
    <td><?$row[2]?></td>
    </tr>
    </table>
    <?
    echo "<p>";
    }
    }
    mysql_free_result($result);


    ?>
  • edited 四月 2006
    只有一個疑問:
    mysql_num_rows($result)=="0"
    ??
    mysql_num_rows($result)==0

    下次貼這麼多程式碼的時候記得用附加檔案形式,感謝。
  • edited 四月 2006
    用Dreamweaver作的,所謂的檔案是指???
    mysql_num_rows($result)==0
    不用加" " 嗎?他輸出的不是字串喔!
    mysql_num_rows($result)=="0"
    我用這樣去跑可以跑出來!
    用管理員先生的mysql_num_rows($result)==0
    去跑也跑的出來。
    謝謝..........
Sign In or Register to comment.