Jump to content

Recommended Posts

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  :o

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!

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');

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

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.

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!

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?

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.