need a help with a PHP/MySQL issue. I have a table named bids and two column named bidder and tagged both using int.
I’m trying to detect multiple same entry number. I want if a number appears on both of the columns it shouldnt display on the menu list anymore
for example
if the number 4 are in both column
bidder tagged
4 5
2 0
6 4
the 4 above appears like that in the column need the code to check both columns not minding where the data is in the row and not display in the result,
my codes are below
$query = "SELECT b.auction, b.bidder, b.bid, b.tagged, u.nick, u.rate_sum FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder) WHERE b.auction = :auc_id
ORDER BY b.bid asc, b.quantity DESC, b.willwin asc"; $params = array(); $params[] = array(':auc_id', $id, 'int');
$i = 0;
$hbidder_data = array();
foreach ($db->fetchall() as $bidrec)
{
if (!isset($bidderarray[$bidrec['nick']]))
{
if ($system->SETTINGS['buyerprivacy'] == 'y' && (!$user->logged_in || ($user->user_data['id'] != $auction_data['user'] && $user->user_data['id'] != $bidrec['bidder'])))
{
$bidderarray[$bidrec['nick']] = $bidrec['nick'];
$bidderarraynum++;
}
}
$template->assign_block_vars('tag_bidder', array(
'BGCOLOUR' => (!($i % 2)) ? '' : 'class="alt-row"',
'ID' => $bidrec['bidder'],
'NAME' => $bidderarray[$bidrec['nick']]
));
$i++;
}
I’m struggling to see how the list of two numbers relates to the code you posted. I think the way I’d do it is run down each element in the first column and see if it exists anywhere in the second column, and if it does, remove it from the menu. That would be quite easy if you have three separate arrays - one containing the first column, another containing the second, and a third containing the menu list contents. How feasible that is depends on how many entries there will be in those two columns of numbers.
oh and they dont relate thats the code i use to list users and also remove a users name from the list(users viewing a page dont get to see there own name on it) only other names.
foreach over your array. remember every left-value in an array $lefts.
if you need the comparison in both directions, put the right value in $rights. foreach over your array again. if the right value is in_array() the $lefts, store the number in a seperate array $excludes. if the left value is in the $rights, also store the number in $excludes.
that’s not very efficient (array_column()/array_intersect()/array_diff() may help), but will do the job.
OK, but that isn’t clear. The query and code you posted doesn’t look like the code of a beginner. It’s often difficult to tell how much knowledge a poster has. Perhaps you could start by posting the code that generates the list of two columns of numbers that you want to search through.