johnson.sh Posted September 7, 2009 Share Posted September 7, 2009 Hi all! I'm trying to fetch the first item from MSSQL table, save it into php variable and then delete it from the table: table name - tblMACJumpPool [ intBlockID(int), strMac(varchar12) ] values: 12,1 12,2 12,3 12,4 My Code: [code <?php include("connect.php"); include("head.php"); function GetJumpMAC($block_id) { $get_jump_query = "SELECT strMAC FROM tblMACJumpPool WHERE intBlockID = '$block_id'"; $get_jump_result = mssql_query($get_jump_query) or die('Error, select query failed'); while($row_jump = mssql_fetch_array($get_jump_result, MSSQL_ASSOC)) { $jump = "{$row_jump['strMAC']}"; return $jump; //echo "Current-->" . $jump . "<br>"; } } $counter=1; $get_n=1; $get_b_id=12; while ($counter <= $get_n) { $jumpmac = GetJumpMAC($get_b_id); //$jumpmac='2'; $delete_query = "DELETE FROM tblMACJumpPool WHERE strMac = '$jumpmac'"; mssql_query($delete_query) or die('Error, delete query failed'); $counter++; } Now the problem is that when i run this php page, 2 rows being deleted instead of 1! when i remove the include for 'head.php' all works fine, but this file included in all of my pages.. also when i unmark //$jumpmac='2'; , it will delete only 1 row as it suppose to do. so i'm very confused I done it lots of times and it worked this way, but this time it doesn't work good. Hope you can help me, thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/ Share on other sites More sharing options...
ignace Posted September 7, 2009 Share Posted September 7, 2009 Both your function and your code is wrong: Your function should be: function GetJumpMAC($block_id) { $get_jump_query = "SELECT strMAC FROM tblMACJumpPool WHERE intBlockID = '$block_id'"; $get_jump_result = mssql_query($get_jump_query) or die('Error, select query failed'); $row = mssql_fetch_array($get_jump_result, MSSQL_ASSOC); return $row['strMac']; } And your code should be: $get_b_id=12; $jumpmac = GetJumpMAC($get_b_id); $delete_query = "DELETE FROM tblMACJumpPool WHERE strMac = '$jumpmac'"; mssql_query($delete_query) or die('Error, delete query failed'); As a result you'd get: include("connect.php"); include("head.php"); function GetJumpMAC($block_id) { $get_jump_query = "SELECT strMAC FROM tblMACJumpPool WHERE intBlockID = '$block_id'"; $get_jump_result = mssql_query($get_jump_query) or die('Error, select query failed'); $row = mssql_fetch_array($get_jump_result, MSSQL_ASSOC); return $row['strMac']; } $get_b_id=12; $jumpmac = GetJumpMAC($get_b_id); $delete_query = "DELETE FROM tblMACJumpPool WHERE strMac = '$jumpmac'"; mssql_query($delete_query) or die('Error, delete query failed'); Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-913986 Share on other sites More sharing options...
johnson.sh Posted September 7, 2009 Author Share Posted September 7, 2009 Hey ignace thanks for the quick reply. nothing changed, it still doesn't work and deleting 2 rows instead of 1. btw, strMac = strMAC in MSSQL query? Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-913995 Share on other sites More sharing options...
Mark Baker Posted September 7, 2009 Share Posted September 7, 2009 nothing changed, it still doesn't work and deleting 2 rows instead of 1. btw, strMac = strMAC in MSSQL query? Clearly two rows in the tblMACJumpPool table match the criteria you're specifying in the WHERE clause of the delete statement. They may well have different block IDs, but the same value for strMac Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-913998 Share on other sites More sharing options...
Adam Posted September 7, 2009 Share Posted September 7, 2009 If you're asking if fields are case-sensitive, no they're not.. However on the PHP side, array keys are. You may want to use either print_r or var_dump to double check the values if you're having problems there. Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-914002 Share on other sites More sharing options...
johnson.sh Posted September 7, 2009 Author Share Posted September 7, 2009 Clearly two rows in the tblMACJumpPool table match the criteria you're specifying in the WHERE clause of the delete statement. They may well have different block IDs, but the same value for strMac hey Mark, i double checked this and there is no duplicate values for strMac. I'm fetching all data from the table after i run the php script to see changes. MrAdam If you're asking if fields are case-sensitive, no they're not.. However on the PHP side, array keys are. You may want to use either print_r() or var_dump() to double check the values if you're having problems there. thanks for the information. Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-914005 Share on other sites More sharing options...
johnson.sh Posted September 7, 2009 Author Share Posted September 7, 2009 Hi all, i went thourgh of head.php file that i inculded on the top of the page. finally i found this line: <table background="#E8EEFA"><td></td><div class="logo"></div></table> after chaning this line to <table bgcolor=#E8EEFA><td></td><div class="logo"></div></table> it all worked! it's quite weird becouse this head.php is working ok on all of my other pages.. if one of you knows why i'll be happy to know! anyway thanks for your help guys! Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-914012 Share on other sites More sharing options...
Adam Posted September 7, 2009 Share Posted September 7, 2009 I think that must be coincidence, it's literally impossible that changing background="..." to bgcolor=".." would have any effect on the results of a database query. Perhaps you'd pasted in duplicate code, removed and then forgot to save until then, or something? Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-914013 Share on other sites More sharing options...
johnson.sh Posted September 7, 2009 Author Share Posted September 7, 2009 I think that must be coincidence, it's literally impossible that changing background="..." to bgcolor=".." would have any effect on the results of a database query. Perhaps you'd pasted in duplicate code, removed and then forgot to save until then, or something? When i don't include the head.php file it's all working. so all i could think of is that something from that file had to do to my problem. It's very strange that this little change made it all work, but until now all of my tests worked great. Quote Link to comment https://forums.phpfreaks.com/topic/173384-solved-problem-fetching-string-from-mssql/#findComment-914015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.