Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,201,430 members, 7,978,361 topics. Date: Friday, 18 October 2024 at 06:57 AM |
Nairaland Forum / Science/Technology / Programming / Already Exist Dont Display 3000 k naira for who can solve it (1473 Views)
Who Can Solve This Problem Using Java / Already Exist Remove From List / Already Exist Remove From List (2) (3) (4)
Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 8:20am On May 03, 2017 |
need a help with a PHP/MySQL issue. I have a table named bids and two column named buyer and tagged both using int. buyer -------------- 8 5 2 tagged -------------- 5 4 1 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, like the 5 above hope yo understand. Any tip? code below $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'); |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 11:36am On May 03, 2017 |
Fetch both table as an associative array. Then use: For each element in array 1; Use in_array() to check if it appears in array2 Goodluck skyhighweb. |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 12:03pm On May 03, 2017 |
fleshbone:plz how do i go about that? |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 1:28pm On May 03, 2017 |
skyhighweb:Its being a while I did php/mysqli. Assuming u hav ur db connection setup already! $select_statement = "select * from table_name"; $result_statement = mysqli_query($db_connection, $select_statement); If(mysqli_num_rows($result_statement) > 0){ $all_table = mysqli_fetch_assoc($result_statement); } Else{ Echo "Zero Rows in table1" } $select_statement2 = "select * from table_name2"; $result_statement2 = mysqli_query($db_connection, $select_statement2); If(mysqli_num_rows($result_statement2) > 0){ $all_table2 = mysqli_fetch_assoc($result_statement2); } Else{ Echo "Zero Rows in table2" } Foreach ($all_table1['column_name'] as $data_held){ If in_array($data_held, $all_table2['column_name']){ Echo 'yes' //this will echo yes each time it encounter any. } Else{ Echo 'No' // for each that wasn't found. } } Try this, I hope it helps, I haven't tried it though. |
Re: Already Exist Dont Display 3000 k naira for who can solve it by vicsrael: 2:00pm On May 03, 2017 |
skyhighweb:have my SQL query for that no duplicate select from multiple tables |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 2:23pm On May 03, 2017 |
vicsrael:hmmm |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 2:27pm On May 03, 2017 |
fleshbone:hi thanks for the effort but am talking more of columns here not two tables but too columns |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 2:49pm On May 03, 2017 |
skyhighweb: The code should be shorter then: $select_statement = "select * from table_name"; $result_statement = mysqli_query($db_connection, $select_statement); If(mysqli_num_rows($result_statement) > 0){ $column1 = mysqli_fetch_assoc($result_statement['column_name1']); $column2 = mysqli_fetch_assoc($result_statement['column_name2']); } Else{ Echo "Zero Rows in table1" } Foreach ($column1 as $data_held){ If in_array($data_held, $column2){ Echo 'yes' //this will echo yes each time it encounter any. } Else{ Echo 'No' // for each that wasn't found. } } Try this then. |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 3:20pm On May 03, 2017 |
fleshbone: hi sorry for bugging u and i tried the above didnt getting any output i guess am doing something wrong, heres the code am using 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"', 'NAME' => $bidderarray[$bidrec['nick']], 'ID' => $bidderarray[$bidrec['id']] )); $i++; } that display users name but when they show up in both columns (buyer and tagged) i dont want them to show up on the list, so u like comparing two columns in a table. thanks |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 4:13pm On May 03, 2017 |
skyhighweb: Am not good with object oriented aspect of mysqli. Am sorry I don't understand some few syntax above! |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 4:36pm On May 03, 2017 |
fleshbone: hi ok i implemented where buyer != tagged, but it isnt working right it only works if the number are on the same roll eg wont work like this buyer 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 but works like this i altered it just to check and it works but not the way it should(works cause i put 4 in the same roll buyer tagged 4 4 2 0 6 5 |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 4:40pm On May 03, 2017 |
fleshbone: |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 4:59pm On May 03, 2017 |
skyhighweb: Then there must be a problem with ur foreach statement. Check the foreach statement again. Fetch the buyer into an associative_array, and tagged into another. Try using this method (in_array()) in the code. Foreach (buyer as buyer_value){ If ( in_array(buyer_value, tagged)){ Echo buyer_value.' In tagged'; } Else{ Echo 'no buyer element in tagged' } } This should work. Please study carefully and apply. Thanks |
Re: Already Exist Dont Display 3000 k naira for who can solve it by yorex2011: 5:03pm On May 03, 2017 |
skyhighweb try This SQL Statement for the first part SELECT `buyer`, `tagged`, `auction`, `bidder`, `willwin` FROM `bids` WHERE `buyer` NOT IN (SELECT `tagged` FROM `bids`) AND `tagged` NOT IN (SELECT `buyer` FROM `bids`) This code will return only rows that do not have values of buyers in tagged..it will also ignore rows where the duplication occured ie 8 0 2 0 5 0 7 5 8 4 9 1 would return 8 0 2 0 8 4 9 1 Full code should then be SELECT `buyer`, `tagged` FROM `bids` WHERE `buyer` NOT IN (SELECT `tagged` FROM `bids`) AND `tagged` NOT IN (SELECT `buyer` FROM `bids`) LEFT JOIN " . $DBPrefix . "users u ON (u.id = bids.bidder) WHERE bids.auction = :auc_id ORDER BY bids.bid asc, bids.quantity DESC, bids.willwin asc Always try to use SQL to get data, avoid using php to do stuff that SQL can do, its faster and better, just imagine if you had 1million rows lol... |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 9:05pm On May 03, 2017 |
yorex2011:hi i just implemented urs didnt work (sad face) |
Re: Already Exist Dont Display 3000 k naira for who can solve it by yorex2011: 9:08pm On May 03, 2017 |
skyhighweb: You prolly didn't do it properly.. Go to your backend and test the first mysql select.. Before adding others You can try play with brackets |
Re: Already Exist Dont Display 3000 k naira for who can solve it by yorex2011: 9:11pm On May 03, 2017 |
skyhighweb: post the table structures lets fully see.. If you can |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 9:58pm On May 03, 2017 |
yorex2011:$query = "SELECT b.id, b.bidder, b.tagged, b.willwin, b.auction, 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'); $db->query($query, $params); foreach ($db->fetchall() as $bidrec) { if (!isset($bidderarray[$bidrec['nick']])) { if ($user->user_data['id'] != $bidrec['bidder']) { $bidderarray[$bidrec['bidder']] = $bidrec['bidder']. ' ' . $bidderarray[$bidrec['']] = $bidrec['nick']. ' ' . $bidderarray[$bidrec['']] = $bidrec['willwin']; } } $template->assign_block_vars('tag_bidder', array( 'BGCOLOUR' => (!($i % 2)) ? '' : 'class="alt-row"', 'ID' => $bidderarray[$bidrec['bidder']], 'NAME' => $bidderarray[$bidrec['nick']], 'TAGGED' => $bidrec['tagged'] )); } table structure as below Table name is bids columns are id(int) auction(int) bidder(int) bid(double) bidwhen(varc) willwin(text) tagged(int) balance(int) thats the full code and i changed the column from buyer to bidder |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 11:08am On May 04, 2017 |
no solution yet programmers |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 3:34pm On May 04, 2017 |
Its sad I couldn't help. I have no idea about PDO. |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 4:10pm On May 04, 2017 |
fleshbone:am not using pdo |
Re: Already Exist Dont Display 3000 k naira for who can solve it by fleshbone(m): 4:13pm On May 04, 2017 |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 4:26pm On May 04, 2017 |
fleshbone:sorry i meant they are aa bit similar |
Re: Already Exist Dont Display 3000 k naira for who can solve it by delino12(m): 4:32pm On May 04, 2017 |
Using a while loop is the solution. Selecting for a single table first query on auction table for row. Obtaining result via array fetching data using while loop then nest the second query at the false outcome if the number of rows return is true. Then u are good to good. Simple PHP & MySQL illustration Contact me on 09092367163 <?php /* * Delino * Lizards network */ class DBconnect{ protected $host; protected $user; protected $pass; protected $database; public function __construct() { $this->host = "localhost"; $this->user = "root"; $this->pass = ""; $this->database = "test_auction"; } public function iConnect() { $iConnect = mysqli_connect( $this->host, $this->user, $this->pass, $this->database ); if(mysqli_connect_errno()) { return "Error creating connection ! <br />".mysqli_connect_error(); } return $iConnect; } } /** * Bids Class */ class Bid extends DBconnect { protected $plug; public function __construct() { # code... parent::__construct(); $this->plug = DBconnect::iConnect(); } public function checkBids($buyer_no, $tagged_no) { //defensive programming check if two numbers are the same if($buyer_no == $tagged_no){ echo 'Error try refreshing the webpage'; }else{ // check buyers $check_buyer_no = " SELECT * FROM bids "; $check_buyer_no .= " WHERE(buyer = '".$buyer_no."' || tagged_no= '".$buyer_no."' "; // using OR for comparison $check_buyer_no .= " AND tagged ='".$tagged_no."' || buyer ='".$tagged_no."' ) "; // using OR for comparison $check_buyer_no_query = mysqli_query($this->plug, $check_buyer_no); if(!$check_buyer_no_query){ // return error if query fail echo 'Error running the check buyer query <br />'.mysqli_error($this->plug); }elseif(mysqli_num_rows($check_buyer_no_query)){ // fetch numbers echo 'Duplicates Found <br />'; // now fetch data to decide while($bids_details = mysqli_fetch_array($check_buyer_no_query)){ $db_buyer_no = $bids_details['buyer']; $db_tagged_no = $bids_details['tagged']; // u can return if u like. } } } } } $auction = new Bid(); $auction_bids = $auction->checkBids($buyer_no, $tagged_no); ?> |
Re: Already Exist Dont Display 3000 k naira for who can solve it by delino12(m): 5:06pm On May 04, 2017 |
no need to contact me you can see your solve answer on my modify post.. |
Re: Already Exist Dont Display 3000 k naira for who can solve it by skyhighweb(m): 3:54pm On May 05, 2017 |
have figure it out using SELECT * FROM table WHERE col1 NOT IN (SELECT col2 FROM table) WHERE bidder NOT IN (SELECT tagged FROM bids) but rewrote the code to WHERE bidder NOT IN ('tagged') and tagged IN ('bidder') php can be something else, well unto the next coding issue 1 Like |
(1) (Reply)
Tutorials: Learn How To Hack A Gmail Account / Python Programmers, Pls Help Me Out? / Which Lucrative Digital Skill Would You Recommend??
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 56 |