TEENFRONT Posted March 21, 2010 Share Posted March 21, 2010 Hey all Quick help required, probly really easy... Im doing a traffic exchange system for one of my sites and i need to select partners urls that have less "out" hits than they do "in" hits. I track hits elsewhere. The main issue is i want to do the selecting "within" 5 hits. So if site 1 has 15 in and 16 out, i still want to send another hit to this site, as its within "5". if site 2 has 20 hits in and 24 hits out, this is ok. if site 3 has 20 hits in and 26 hits out, this is not ok (because in is over 5 from out) and doesnt want selecting. The code i have at the moment just selects sites that have a less out than in value. $sql = "SELECT * FROM links WHERE `out` < `in` LIMIT 1"; So thats too simple, i want to still select sites that out is within 5 more of in. More than confused. Quote Link to comment Share on other sites More sharing options...
Bottyz Posted March 21, 2010 Share Posted March 21, 2010 why not selected all from db and use a foreach loop to work out the difference between the two values and if they are then output whatever you wanted, whereas if not just go to the next record? Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted March 21, 2010 Share Posted March 21, 2010 $selecthits="SELECT * from links where siteid='$sid'"; $selecthits2=mysql_query($selecthits); $selecthits3=mysql_fetch_array($selecthits2); $hitsin = $selecthits3[hitsin]; $infactor = $hitsin + 5; $sql = "SELECT * FROM links WHERE hitsout <= '$infactor'"; Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted March 21, 2010 Share Posted March 21, 2010 SELECT * FROM `links` WHERE (`out` - `in`) <= 5 Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted March 21, 2010 Author Share Posted March 21, 2010 SELECT * FROM `links` WHERE (`out` - `in`) <= 5 That looks something like what i need! Il go try it now, cheers! Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted March 21, 2010 Share Posted March 21, 2010 No problem @Bottyz - Using the method you suggested is going to be a huge waste on resources which is why it's not really ideal Quote Link to comment Share on other sites More sharing options...
Bottyz Posted March 21, 2010 Share Posted March 21, 2010 @jay6390 I agree, your method is much simpler. I may have a look to see if any of my scripts can be sped up the same way! thanks. Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted March 21, 2010 Share Posted March 21, 2010 me too Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted March 21, 2010 Share Posted March 21, 2010 No problem. You should always try to make your queries as efficient as possible, to reduce your php processing as much as possible and conserve memory Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted March 21, 2010 Share Posted March 21, 2010 Also unless you are actually using the numerical indexes of your selected columns, you should use mysql_fetch_assoc instead of mysql_fetch_array, as it just returns duplicate data (again wasting memory) Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted March 21, 2010 Author Share Posted March 21, 2010 works perfect! thanks so much mate! i have to dash out quickly but im guessing it i wanted to replace the "5" with a field that had other set numbers in, id just literally do SELECT * FROM `links` WHERE (`out` - `in`) <= `margin` ? Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted March 21, 2010 Share Posted March 21, 2010 Yes you would. However you would have to have that margin field in every row but it should work fine Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.