Jump to content

updating a user row, need help.


skyhighweb

Recommended Posts

hello programmers am having an update issue and i dont know how to go about it am gonna try n explain it the way i can plz bear with me.


i have a table called bids and two important column called bidder and tagged

when (bidder 5) has no one to tag he simple drops a bid and when another bidder comes along(bidder 3) he tags (bidder 5) i want bidder 5 row to update showing (bidder 3)in his row.

for example
bidder 5 place bid it looks like this
bidder           tagged 
5                    0    

no one to tag so it shows zero

i want if bidder 5 get tagged by bidder 3 it update showing the person that tag bidder 5 and it will look like this
bidder            tagged
5                     3

from the image i attached u can simply understand what am saying.

looking forward to ur replies thanks

code i am using to fill the form is below

 

// tag someone
$query = "SELECT b.*, u.nick FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
WHERE b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder') and b.auction = :auc_id ";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);

$i = 0;
while ($row = $db->fetch())
{
	$template->assign_block_vars('tag_bidder', array(
			'ID' => $row['bidder'],
			'NAME' => $row['nick'],
			'TAGGED' => $row['tagged']
			));
	$i++;
}

biddertaggedimage.png

Link to comment
Share on other sites

hi programmer i have an issue here.
so let me explain better, if david place a bid but doesnt tag any one the column looks like this

bidder......tagged
david ..... 0

and if someone else(mike), place a bid and tag david

the column look like this

bidder......tagged
Mike ..... david

this shows both mikes and david rows
bidder......tagged
david ..... 0
mike ..... david

u can see david row doesnt update, it should show mike and not 0, hope u understand.

below is the code am using to fill the form

// tag someone
$query = "SELECT b.*, u.nick FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
WHERE b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder') and b.auction = :auc_id ";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);

$i = 0;
while ($row = $db->fetch())
{
    $template->assign_block_vars('tag_bidder', array(
            'ID' => $row['bidder'],
            'NAME' => $row['nick'],
            'TAGGED' => $row['tagged']
            ));
    $i++;
}

Link to comment
Share on other sites

i have tried updating but it doesnt work 

i tried this bids

set tagged = (bidder)

the data looks like this

bidder......tagged
david ..... david
mike ..... david

instead of

bidder......tagged
david ..... mike
mike ..... david

Link to comment
Share on other sites

Show the complete code you're using.  An update query is how you update the database, so if you're updating the wrong column or giving it the wrong value then maybe that will be apparent by looking at your code.

Link to comment
Share on other sites

good morning all, here is the complete code

 
 
 
135.png

 

$query = "SELECT b.*, u.nick FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
WHERE b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder') and b.auction = :auc_id ";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);				
// Also update bids table
				$query = "INSERT INTO " . $DBPrefix . "bids VALUES (NULL, :auc_id, :bidder_id, :bid, :time, :qty, :willwin, :tagged, :balance)";
				$params = array();
				$params[] = array(':bid', $bid, 'float');
				$params[] = array(':auc_id', $id, 'int');
				$params[] = array(':bidder_id', $bidder_id, 'int');
				$params[] = array(':time', $NOW, 'int');
				$params[] = array(':qty', $qty, 'int');
				$params[] = array(':willwin', $willwin, 'str');
				$params[] = array(':tagged', $tagged, 'str');
				$params[] = array(':balance', $balance, 'str');
				$db->query($query, $params);


$i = 0;
while ($row = $db->fetch())
{
	$template->assign_block_vars('tag_bidder', array(
			'ID' => $row['bidder'],
			'NAME' => $row['nick'],
			'WILLWIN' => $row['willwin'],
			'TAGGED' => $row['tagged']
			));
	$i++;
}
Link to comment
Share on other sites

arr jeez sorry wrong code tot i copied it right so sorry heres d code i use

 

// tagged

$query = "SELECT b.*, u.nick FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "bids_tagged bt ON (bt.id = b.bidder)
WHERE b.bidder NOT IN ('b.tagged') and b.tagged IN ('bt.bidder') and b.auction = :auc_id ";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);
                
if ($bidder = $tagged)
            {
                
                
                // Also insert bids_tagged table
                $query = "INSERT INTO " . $DBPrefix . "bids_tagged VALUES (NULL, :auc_id, :bidder_id, :bid, :time, :qty, :willwin, :tagged, :balance)";
                
                $params = array();
                $params[] = array(':bid', $bid, 'float');
                $params[] = array(':auc_id', $id, 'int');
                $params[] = array(':bidder_id', $bidder_id, 'int');
                $params[] = array(':time', $NOW, 'int');
                $params[] = array(':qty', $qty, 'int');
                $params[] = array(':willwin', $willwin, 'str');
                $params[] = array(':tagged', $tagged, 'int');
                $params[] = array(':balance', $balance, 'int');
                $db->query($query, $params);
                
                    // update bids
        $query = "UPDATE " . $DBPrefix . "bids SET bidder = (tagged)";
                $params[] = array(':auc_id', $id, 'int');
                $db->direct_query($query);    
            }                
            
$i = 0;
while ($row = $db->fetch())
{
    $template->assign_block_vars('tag_bidder', array(
            'ID' => $row['bidder'],
            'NAME' => $row['nick'],
            'WILLWIN' => $row['willwin'],
            'TAGGED' => $row['tagged']
            ));
    $i++;
}

Link to comment
Share on other sites

You need a WHERE condition to identify what records need updating, else ALL records will be targeted. You should be getting the id of record affected, and new value for that specific column, Similar to "UPDATE " . $DBPrefix . "bids SET bidder = ".$newTaggedvalue." WHERE userid = ".$id

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...