skyhighweb Posted May 7, 2017 Share Posted May 7, 2017 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++; } Link to comment Share on other sites More sharing options...
skyhighweb Posted May 7, 2017 Author Share Posted May 7, 2017 any idea how to go about this Link to comment Share on other sites More sharing options...
skyhighweb Posted May 8, 2017 Author Share Posted May 8, 2017 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 More sharing options...
dsonesuk Posted May 8, 2017 Share Posted May 8, 2017 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. Link to comment Share on other sites More sharing options...
skyhighweb Posted May 8, 2017 Author Share Posted May 8, 2017 help still needed Link to comment Share on other sites More sharing options...
justsomeguy Posted May 8, 2017 Share Posted May 8, 2017 You use an UPDATE query to update the database. Link to comment Share on other sites More sharing options...
skyhighweb Posted May 9, 2017 Author Share Posted May 9, 2017 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 More sharing options...
justsomeguy Posted May 9, 2017 Share Posted May 9, 2017 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 More sharing options...
skyhighweb Posted May 10, 2017 Author Share Posted May 10, 2017 good morning all, here is the complete code skyhighweb 21h 1 $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 More sharing options...
skyhighweb Posted May 10, 2017 Author Share Posted May 10, 2017 thats the code i use for insert updating it doesnt work fine Link to comment Share on other sites More sharing options...
dsonesuk Posted May 10, 2017 Share Posted May 10, 2017 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. Link to comment Share on other sites More sharing options...
skyhighweb Posted May 10, 2017 Author Share Posted May 10, 2017 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 More sharing options...
skyhighweb Posted May 10, 2017 Author Share Posted May 10, 2017 please closed already solved thanks for ur effort Link to comment Share on other sites More sharing options...
dsonesuk Posted May 10, 2017 Share Posted May 10, 2017 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 More sharing options...
skyhighweb Posted May 10, 2017 Author Share Posted May 10, 2017 yeah it was missing a user_id thanks peeps Link to comment Share on other sites More sharing options...
justsomeguy Posted May 15, 2017 Share Posted May 15, 2017 And that if statement is not comparing $bidder with $tagged, it is changing the value of $bidder. $bidder will always be equal to $tagged. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now