$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++;
}
sorry mod for the multiple post
OK, so straight after you execute the INSERT query, you need an UPDATE query to set the ātaggedā column for the other user.
yeah thatās where d problem is its not even updating sometimes i get zeros btw bidder n tagged when i tweak the code thats y i gave posted only d select n insert cuz i have no luck on d updating part
Well, I guess the query would be something like
update bids set tagged = bidder_id where auction = auc_id and bidder = tagged
That presumes that within a single auction (auc_id) the bidder will be unique.
yeah they are both unique id ,i just tried the code it didnt work (sadface)
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
not yet good
what u think is missing
morning all, still on the issue
Show us the current code.
am still using the above code
skyhighweb
1d1
$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']
));
No, I meant show the code that you have tried with the āupdateā query that you said youād used back in post #25 , that produced the results you showed in post #26 .
Looks like itās the home-brewed wrapper to blame. Making it to keep the state is a sure way to make your code execution a mess.
Almost every PHP user, while learning OOP, is trying to create a DB wrapper of their own. Although a good idea by itself, it leads to numerous mistakes, caused by the lack of practical experience.
The preferred remedy would be to throw the whole wrapper away and to use vanilla PDO instead. Or at least to make it return all rows at once instead of fetching rows one by one, if possible.
// tagged
$query = "SELECT b.*, u.nick, bt.tagged, bt.auction FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "bids_tagged bt ON (bt.tagged = u.id)
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);
if ($bidder = $tagged)
{
// Also insert 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);
// 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++;
}
i later realise it only making a copy of a row and insert it on the next thats bidder copies it self and place on the row next to it which is tagged.
hi thanks for ur reply but am totally lost with what u just wrote, like missed my way.
updated code with update bids table
// 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++;
}
Off Topic
@skyhighweb : when you post code on the forums, you need to format it so it will display correctly.
You can highlight your code, then use the </>
button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards donāt have that character.
sorry about that but am using mobile phone how do i do that with phone
No need to apologise.
Do you have the backtick character ` on your phone? If so, you can use that. You can also touch the āhamburgerā menu in the top right corner of the reply window, which will open the toolbar with all the buttons.
1 Like
This bit is just not correct:
$query = "UPDATE " . $DBPrefix . "bids SET bidder = (tagged)";
$params[] = array(':auc_id', $id, 'int');
$db->direct_query($query);
You have an update query, but you havenāt restricted it to update only the appropriate record in the bids
table, you need to only do the update where the auction id is the same, and the bidder is the one who you tagged. You havenāt specified any values in there, either.
$query = "UPDATE " . $DBPrefix . "bids SET tagged = :tuser where auction = :auc_id and bidder = :tag";
$params[] = array(':tuser', $bidder_id, 'int');
$params[] = array(':auc_id', $id, 'int');
$params[] = array(':tag' , $tagged, 'int');
$db->query($query, $params);
might do it, but Iām not that familiar with the way you use prepared statements. Check the column names and variable names, Iām reasonably sure thatās correct but not completely.