2011-05-11 48 views
1

我有以下由其他人創建的代碼,儘管它看起來像變量被傳遞,但結果集中沒有返回任何東西; 頁面: http://www.libraries.uc.edu/research/subject_resources/art/db/index.php ...然後做一個搜索。 下面是結果頁面上的代碼(長度稍微編輯)。我有一種感覺,這是引號等等,但已經忽略了一些東西!mysql中的動態php變量,sql-vars被設置,但結果集爲空?

<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 
if (isset($_GET['stval'])) { 
    $stval_Recordset1 = (get_magic_quotes_gpc()) ? $_Get['stval'] : addslashes($_Get['stval']); 
} 


if (isset($_GET['stval'])) { 
    $stval_Recordset1 = $_GET['stval']; 
} 

if (isset($_GET['sq'])) { 
    $sq_Recordset1 = $_GET['sq']; 
} 
mysql_select_db($database_daap_photo, $daap_photo); 
$query_Recordset1 = sprintf("SELECT * FROM main WHERE %s = %s ", GetSQLValueString($stval_Recordset1, "text"),GetSQLValueString($sq_Recordset1, "text")); 
$Recordset1 = mysql_query($query_limit_Recordset1, $daap_photo) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 

?> 

然後在身體:

<?php print_r($_GET); 
if(isset($_GET["stval"])) echo "stval is set\n"; 
    if(isset($_GET["sq"])) echo "sq is set\n"; 

?> 
<table width="100%" border="0" cellpadding="2" cellspacing="2"> 
    <tr bgcolor="#CCCCCC"> 
    <td colspan="4" bgcolor="#FFFFFF"><h1>Art</h1> 
     <h2>Photography Images Slide Collection -Search Results </h2>  
     <p align="left" class="style1">Your search returned <strong></strong> records.<br /> 
     |<br /> 
     </p> 
     <p align="left" class="style1">Your search returned no results. Please 
     use your browsers back button to search again. </p> 
     <p>&nbsp;First | Previous | Next | Last<br /> 
     <br /> 
     </p></td> 
    <td bgcolor="#FFFFFF">&nbsp;</td> 
    </tr> 
    <tr bgcolor="#CCCCCC"> 
    <td bgcolor="#CCCCCC"><p><strong>Last Name </strong></p> 
     </td> 
    <td bgcolor="#CCCCCC"><strong>First Name </strong></td> 
    <td bgcolor="#CCCCCC"><strong>Dates</strong></td> 
    <td bgcolor="#FFFFFF">&nbsp;</td> 
    <td bgcolor="#FFFFFF">&nbsp;</td> 
    </tr> 
    <tr bgcolor="#CCCCCC"> 
    <td bgcolor="#FFFFFF">&nbsp;</td> 
    <td><strong>Nationality</strong></td> 
    <td><strong>Subject</strong></td> 
    <td><strong>Quantity</strong></td> 
    <td><strong>Media</strong></td> 
    </tr> 
    <?php do { ?> 
    <tr> 
    <td class="bold"><?php echo $row_Recordset1['LAST_NAME']; ?></td> 
    <td><?php echo $row_Recordset1['FIRST_NAME']; ?></td> 
    <td><?php echo $row_Recordset1['DATES']; ?></td> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 

等....

謝謝!

+0

你可以打印出來:$ query_Recordset1(查詢)我覺得你不是在查詢 – 2011-05-11 19:12:14

回答

0

嘗試更改查詢

SELECT * FROM main WHERE %s = '%s' 
+0

,導致封閉值:您的SQL語法錯誤;檢查對應於您的MySQL服務器版本的手冊,以便在第1行的'Eddie''LIMIT 0,0'處使用正確的語法 – LisaH 2011-05-11 19:17:35

+0

Hm ..也許這個LIMIT 0,0中存在問題? =) – rMX 2011-05-11 19:22:56

+0

這就是我的想法!現在嘗試。 – LisaH 2011-05-11 19:33:36