Jump to content

already exist dont display


skyhighweb

Recommended Posts

26 minutes ago, dsonesuk said:

I get what you want! I GOT it from your first opening post in topic. Your other explanations describe a mixture of both of what you want and the opposite, that is why its difficult for other to give correct solution.

The code I have supplied, with sql statement, is what you need to use for accessing required records using your method of accessing database records. The if condition compares values in array with values looped through the foreach loop values.

but it showing error or am i implementing it wrong? can u implement for me in my code i added above? so i know what am doing wrong

Link to comment
Share on other sites

Just now, dsonesuk said:

My code uses pdo prepared method, if you just copy and paste it probably won't work, but I can't tell because I am not procession of the power of mind reading or the force.

mind reading as in? some one drop this code

buyer != tagged that works if the value are on the same line eg

bidder   tagged

2            1

4            4

8            6

with the 4 like it works isnt there anycode that can check even its on the last row? and like i said b4 am a newbie so given me a code will simply means copy n pasting with little edit

 

 

 

Link to comment
Share on other sites

13 minutes ago, skyhighweb said:

mind reading as in? some one drop this code

buyer != tagged that works if the value are on the same line eg

bidder   tagged

2            1

4            4

8            6

with the 4 like it works isnt there anycode that can check even its on the last row? and like i said b4 am a newbie so given me a code will simply means copy n pasting with little edit

 

 

 

WHICH is exactly what I have giving you, sql version, and sql with php filtering version, all you have to edit it to work with your existing code method.

Link to comment
Share on other sites

40 minutes ago, dsonesuk said:

WHICH is exactly what I have giving you, sql version, and sql with php filtering version, all you have to edit it to work with your existing code method.

heres the ccomplete code 

$query = "SELECT b.auction, b.buyer, 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++;
}

 

am a newbie am still figuring out php thats d code i use for the form plz intergrate for me thanksm, sorry for the stress

Link to comment
Share on other sites

19 minutes ago, dsonesuk said:

This is the same original code you have been showing from the start? WHERE is the code where you integrated OUR code, but error comes up? The idea is to learn not get us to do all the work for you.

oh i see, and ur code are pdo am using mysql i believe thats y am seeing d error

Link to comment
Share on other sites

There are several ways you can handle this.  You can do everything in SQL, or like already suggested you can also just get a list of the values in one column and then filter things out in PHP.  If you're just starting out and you haven't learned SQL then this isn't going to make a lot of sense.

SELECT * FROM table WHERE col1 NOT IN (SELECT col2 FROM table)

Look at that and try to understand what it's doing, it will select everything from the table except rows where the value in col1 is in any other row in col2 in the same table.  It sounds like that's what you're looking for, hopefully you can adapt that to your database.

Link to comment
Share on other sites

18 hours ago, justsomeguy said:

There are several ways you can handle this.  You can do everything in SQL, or like already suggested you can also just get a list of the values in one column and then filter things out in PHP.  If you're just starting out and you haven't learned SQL then this isn't going to make a lot of sense.

 


SELECT * FROM table WHERE col1 NOT IN (SELECT col2 FROM table)

 

Look at that and try to understand what it's doing, it will select everything from the table except rows where the value in col1 is in any other row in col2 in the same table.  It sounds like that's what you're looking for, hopefully you can adapt that to your database.

i tried what u gave me but no result, i implemented it like this


$query = "SELECT * FROM bids WHERE bidder NOT IN (SELECT tagged FROM bids)";
$params = array();
$db->query($query, $params);

$i = 0;
while ($row = $db->fetch())
{
    $template->assign_block_vars('tag_bidder', array(
            'BGCOLOUR' => (!($i % 2)) ? '' : 'class="alt-row"',
            'ID' => $row['bidder'],
            'TAGGED' => $row['tagged']
            ));
    $i++;
}

 

Edited by skyhighweb
Link to comment
Share on other sites

29 minutes ago, skyhighweb said:

i tried what u gave me but no result, i implemented it like this


$query = "SELECT * FROM bids WHERE bidder NOT IN (SELECT tagged FROM bids)";
$params = array();
$db->query($query, $params);

$i = 0;
while ($row = $db->fetch())
{
    $template->assign_block_vars('tag_bidder', array(
            'BGCOLOUR' => (!($i % 2)) ? '' : 'class="alt-row"',
            'ID' => $row['bidder'],
            'TAGGED' => $row['tagged']
            ));
    $i++;
}

 

 

table.jpg

Link to comment
Share on other sites

18 hours ago, justsomeguy said:

There are several ways you can handle this.  You can do everything in SQL, or like already suggested you can also just get a list of the values in one column and then filter things out in PHP.  If you're just starting out and you haven't learned SQL then this isn't going to make a lot of sense.

 


SELECT * FROM table WHERE col1 NOT IN (SELECT col2 FROM table)

 

Look at that and try to understand what it's doing, it will select everything from the table except rows where the value in col1 is in any other row in col2 in the same table.  It sounds like that's what you're looking for, hopefully you can adapt that to your database.

i think i got it using ur idea still running to see nothing freaking is on, i did this

WHERE bidder NOT IN ('tagged') and tagged IN ('bidder')";

Link to comment
Share on other sites

19 hours ago, justsomeguy said:

There are several ways you can handle this.  You can do everything in SQL, or like already suggested you can also just get a list of the values in one column and then filter things out in PHP.  If you're just starting out and you haven't learned SQL then this isn't going to make a lot of sense.

 


SELECT * FROM table WHERE col1 NOT IN (SELECT col2 FROM table)

 

Look at that and try to understand what it's doing, it will select everything from the table except rows where the value in col1 is in any other row in col2 in the same table.  It sounds like that's what you're looking for, hopefully you can adapt that to your database.

the simple code seem to help i did it this was thou

WHERE col1 NOT IN (' col2 ') and col2 IN (' col2 ')

Link to comment
Share on other sites

You are using a mish mash of PDO, Prepared and plain MYSQLI coding

IF $db is like

$db = new mysqli('host', 'username', 'password', 'database');

then replace these

$params = array();
$db->query($query, $params); 

with

$result = $db->query($query);

and replace

while ($row = $db->fetch()){

with

while ($row = $result->fetch_assoc()) {

Replace the sql with code from 5, 6 posts before.

Link to comment
Share on other sites

I just noticed, from the very first post the columns names were 'buyer' and 'tagged', but! NOW its 'bidder' and 'tagged'???? have you giving wrong column name, did you change the sql to reflect the correct names??? cause that is a reason it did not work before.

Edited by dsonesuk
Link to comment
Share on other sites

WHERE bidder NOT IN ('tagged') and tagged IN ('bidder')

That's going to select every record where the word "tagged" is not in the bidder column, and the word "bidder" is in the tagged column.  I don't think you're looking for the words "tagged" and "bidder".  If you want the values in those columns then you select them like I showed.

As for the result you showed above, that's not correct.  I created a table and inserted the 4 rows you showed with exactly the same data, and I ran the same query, and it did not select rows where the value in bidder is in the tagged column.  It did not select all 4 of those rows, it only selected the 2 with a 0 in the tagged column.  So if it's not working for you, then you're not doing it right.  Just understand what that query is doing, it's not hard to understand.  That's all you need.

Link to comment
Share on other sites

On 05/05/2017 at 7:34 PM, justsomeguy said:

 


WHERE bidder NOT IN ('tagged') and tagged IN ('bidder')

 

That's going to select every record where the word "tagged" is not in the bidder column, and the word "bidder" is in the tagged column.  I don't think you're looking for the words "tagged" and "bidder".  If you want the values in those columns then you select them like I showed.

As for the result you showed above, that's not correct.  I created a table and inserted the 4 rows you showed with exactly the same data, and I ran the same query, and it did not select rows where the value in bidder is in the tagged column.  It did not select all 4 of those rows, it only selected the 2 with a 0 in the tagged column.  So if it's not working for you, then you're not doing it right.  Just understand what that query is doing, it's not hard to understand.  That's all you need.

yeap i changed the name from buyer to bidder n implemented the not in code it working fine now, thanks alot

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...