Jump to content
skyhighweb

updating a user row, need help.

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

Share this post


Link to post
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++;
}

Share this post


Link to post
Share on other sites

No matter how many times you post the same duplicate topic you unlikely to get answer, and risk having these duplicate topics deleted or you being banned.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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++;
}

Share this post


Link to post
Share on other sites

If you use INSERT you are just inserting a new record, not a changing current value in a column of specific current record or row to another value, which UPDATE does.

 

Share this post


Link to post
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++;
}

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

And that if statement is not comparing $bidder with $tagged, it is changing the value of $bidder.  $bidder will always be equal to $tagged.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...