2013-08-29 62 views
0

如果數據庫中存在值,我需要檢查腳本。 該值基於一個變量,該字段爲LONGTEXT。如何檢查特定mysql表的特定列的任何行中是否存在值

// ...:::BEGIN REGISTRATION:::... 

//Add key format for hikashop 
$pay = "PayPal transaction id: $pay"; 

$link = mysql_connect($host, $user, $pass); 
mysql_select_db($dbo); 
if (!$link) 
    { 
    die('Could not connect'); 
    } 

// check if Transaction ID is available on the default website. 
$query = mysql_query ("SELECT * FROM jh23m_hikashop_history WHERE history_data = '$pay'"); 
$result = mysql_num_rows($query); 
echo $result; 

// Verifica che esiste almeno una riga contente la transazione. 
// Se si procedi con la response e salva nel db, altrimenti rispondi che la key non è stata trovata. 
if ($result == 0){ 
    die ('Your transaction has not been found. Please enter your payment transaction correctly or contact the support'); 
} 

奇怪的是,有些價值是找到,但很多不是! $ pay來自$ _POST並且我添加了$ pay =「PayPal transaction id:$ pay」;使其符合商店網站的格式。

請幫助!

編輯:我做了一部分代碼,看看爲什麼這不匹配。 這是通過ARRAY的結果: Array([0] => [1] => 0JW61238FU6854240 [2] => 5EA00979GC149044V [3] => 59P88560S9783170B [4] => 1L697134B06956638 [5] => 1N476458GR470922M [6] = > 3N4412142S083993R [7] => 2GN69713EV7294613 [8] => 9WT48148YE725931K [9] => 585690586Y6998523 [10] => 7X9149767T051513K [11] => 5WJ25963L5455313H [12] => 1L717841BA5989748 [13] => [15] => 78R85507FR2081540 [16] => 96F7363575285431M [17] => 87V99180GV2251342 [18] => 4G459145SE959020V [19] => 86U00726DL9205244 [20] => 70820350T9653825F [21] => 8K002091YN0079914 [22] => 8SD993824R7167708 [23] ] => 93L886231K973983G [24] => 6E98077468505954G [25] => 770172708D596892K [26] => 22N679682U615734D [27] => 3WR4000656945550Y [28] => 59P88560S9783170B => 8H242117S01162917 [30] => 9WC47475K89394047 [31] => > 83L6687699339330K [32] => 1BE09674W4880373N [33] => 3JC01978GH9146509 [34] => 31381161BJ159335S => 17V97629 HJ1941344 [36] => 4XG15144CK988864F [37] => 18625833YF123353H [38] => 2GU86013NN2703635)不matco0JW61238FU6854240

我試過這種腳本來看看爲什麼:

// check if Transaction ID is available on the default website. 
$query = mysql_query ("SELECT * FROM jh23m_hikashop_history"); 
$result = mysql_num_rows($query); 
while(($row = mysql_fetch_array($query))) { 
    $paypal_ids[] =$row['history_data']; 
} 
//print_r ($paypal_ids); 
// ora cerca il valore %pay 
$paypal_ids_split = implode("", $paypal_ids); 
//print_r ($paypal_ids_split); 
$paypal_ids_clean = explode ("PayPal transaction id: ", $paypal_ids_split); 
print_r ($paypal_ids_clean); 

if (in_array($pay, $paypal_ids_clean)){ 
    echo "Match"; 
} else 
{ echo "Does not matco"; 
} 
echo $pay; 

它仍然不匹配? WTF?

但是,如果我用它這匹配! WTF? 含匹配項:59P88560S9783170B

有可能某些字節變髒了嗎?

+1

你做到了這一點,mysql_fetch_array($結果);? – anilCSE

+0

我認爲獨特的可能性是$ pay有時與您的值不匹配並返回0,@anilCSE與mysql_num_rows($ query)就足夠了...... –

+0

順便提一下,DB內部的一些行是空的,可能是問題Emilio? –

回答

0

我有一段時間以前在這個問題上發現的帖子保存了這個文件。

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 

然後你就可以用MYSQL_BOTH切換到數字與MYSQL_NUM或兩者

+0

似乎不工作我敢肯定,即時通訊有問題不是與代碼本身,但與數據字段。由於其中一個是由腳本採取的,因爲我可能手動添加它,而其他人,這是由hikashop軟件添加,可能是不同的......有任何發現可以說「檢查這個$的價值是否存在於這個領域?」不是直接匹配? –

+0

我'我發現我試圖整合的軟件使用:ob_get_clean來保存,這可能會影響字符串的匹配嗎? –

相關問題