Updating a row

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++;
}

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
column

bidder …tagged
5… 0
no one to tag so it shows zero

so if bidder 5 finally get tagged by someone (bidder 3) it update showing the person that tag bidder 5 and it will look like this

column
roll for bidder 5 will look like this

bidder…tagged
5 …3

complete row with bidder5 and bidder 3

bidder…tagged
5 …3
3…5

hope u understand

so, whats the problem with it? is it that you are completely missing any update statement?

take your text as a comment and apply the necessary code.

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

Yes, but where is your code for the “tag” process? That is where, as well as creating the row that shows “mike” tagged “david”, it should update the “david” row to show the link to “mike”.

1 Like

hi thanks for the reply below is the code i use for tagging but havent no idea how to link them

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

That’s not the code to create the “tag” association - it’s not an UPDATE query. That’s just retrieving the information. The section I referred to is where the second row in your post #4 is stored, where you create a row where bidder=mike and tagged=david. That’s the bit where you also need to update bidder=david to set tagged=mike, if I understand correctly.

hi, thats the problem am facing i have not a slight idea how to go about it

thanks chorn for the insight abit heavy for me to decode the article can u help with my code given above? the particular column to alter is the tagged .

if you have been able to write the select statement above, then you can also write the update statement. why dont you even try something yourself?

i did but it doesnt respond, i even created another table hoping the update will reflect over at the new table but it only create a copy and not updating the row which i need

The problem is, the code you posted doesn’t do any updating of anything, so it’s really difficult to figure out what needs to change.

oh okay well the main important once are the bidder n tagged what changes is the tagged which still shows zero instead.

this row btw david n mike after update
bidder…tagged
david … 0
mike … david
u can see the zero there

it should look like this after update

this row btw david n mike
bidder…tagged
david … mike
mike … david

u can see zero changes to mike

so the tagged column is d important one there which connect to bidder, hope am explaining well

Yes, I think I understand what you’re trying to do, it’s just really difficult to suggest what to do without seeing the code that writes to the database table. You obviously have some code that stores a row with bidder=mike and tagged=david, you need to add some code that also updates the row where bidder=david to also write the ‘tagged’ column.

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

the code above i use to write to the database, have tried including update codes but it doesnt make any changes at all.

I don’t see where you are writing to the database in this code. All I see is your retrieving data from the database. Is there more to your code that you are not showing us?

By the way, your code would be easier to read if you firmatted it. Just highlight the code and select the </> icon, that is above the edit area, or place three backticks (`) on the line before the code and three backticks on the line after. I’ve done it for you this time.

No it isn’t. A SELECT query retrieves from the database, an INSERT or UPDATE query stores stuff away.

$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++;
}

yeah sorry about that been using mobile to paste d code some missing here is the full code plus d insert

$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++;
}