Jump to content

Zepo.

Members
  • Posts

    306
  • Joined

  • Last visited

    Never

Everything posted by Zepo.

  1. This is a little confusing so please bear with me. I was thinking of using left.join but couldn't figure out how to implement it properly. I am trying to order all of the results from a table names 'clans' based on how many points the clan has. To calculate the points you have to go into another table 'clanteams' and then loop every team in the clan pulling wins and losses from a row in a specific ladder table. Here is the code i have to calculate the points. $total[wins] = 0; $total[loss] = 0; $members=mysql_query("SELECT id,clanid,teamid,DATE_FORMAT(datejoined,'%M %d, %Y') FROM clanteams WHERE clanid='$member[id]'"); while(list($id,$clanid,$teamid,$joined)=mysql_fetch_row($members)){ $team=mysql_query("SELECT name,ladderid FROM teams WHERE id='$teamid'"); if(mysql_num_rows($team) == 0) continue; $team=mysql_fetch_array($team); $ladder=mysql_query("SELECT name FROM ladders WHERE id='$team[ladderid]'"); $ladder=mysql_fetch_array($ladder); $linfo=mysql_query("SELECT rank,wins,loss FROM ladder_$team[ladderid] WHERE teamid='$teamid'"); $linfo=mysql_fetch_array($linfo); $total[wins] = $total[wins] + $linfo[wins]; $total[loss] = $total[loss] + $linfo[loss]; } $totalpoints = ($total[wins] * 2) - $total[loss]; So now i want to loop through every row in the clans table, and using the above code oder them by $total points. Ive spent hours wrapping my head around it and still cannot figure it out. Please help.
  2. Yes i think i can work with that thank you so much.
  3. Yes but its inserting the two first rows in two other rows when it should insert the first two rows into one row. Here a picture i made
  4. Thank you professor badass, were almost there but it should look similar to this, i know it doesnt work but maybe youll get the idea. <?php $query1 = "SELECT * FROM example1 LIMIT 0, 2"; $result1 = mysql_query($query1) or die(mysql_error()); while($row1 = mysql_fetch_array($result1)){ $query2 = "INSERT INTO example2 (id, name, id2, name2) VALUES('".$row1["id"]."', '".$row1["name"].",".$row2["id"].","$row2["name"]"' ) "; $result2 = mysql_query($query2) or die(mysql_error()); $query3 = "DELETE FROM example1 WHERE id='".$row1["id"]."'"; $query3 = "DELETE FROM example1 WHERE id='".$row2["id"]."'"; $result3 = mysql_query($query3) or die(mysql_error()); } ?>
  5. Anyone please? This seems so easy its just i cant get it to insert without inserting two rows.
  6. Took a break but still have this problem, the two matched rows are random where leagueid=whateever So when a league is started it will go throught and randomly insert into the table from two of the players then delete.........
  7. Pull two rows from same table that have ID and Name. Create a row in different table with both ids and names from first two. Delete the original two rows Make sense?
  8. I thought JOIN was for two different tables....
  9. Heres what I have so far //Start any leagues $leagues=mysql_query("SELECT id,ladder,datestart,hourstart FROM leagues"); while(list($id,$ladderid,$datestart,$hourstart)=mysql_fetch_row($leagues)){ $timenow = date('N', time()); $timenow2 = date('H',time()); if($timenow == $datestart && $timenow2 == $hourstart){ $updatel = mysql_query("SELECT * FROM leagueplayers WHERE league='$id'"); $update2 = mysql_query("SELECT * FROM leagueplayers WHERE league='$id'"); while ($player1 = mysql_fetch_array($updatel) && $player2 = mysql_fetch_array($update2)) { $totalcountleag=mysql_query("SELECT COUNT(*) FROM leagueplayers WHERE league='$id'"); $totalcountleag=mysql_fetch_array($totalcountleag); $totalcountleag="$totalcountleag[0]"; if($totalcountleag >= 2){ $playerd=mysql_query("SELECT * FROM teams WHERE id='$player1[team]'"); $playerd=mysql_fetch_array($playerd); $player2d=mysql_query("SELECT * FROM teams WHERE id='$player2[team]'"); $player2d=mysql_fetch_array($player2d); mysql_query("INSERT INTO challenges (ladderid, challgrid, challgdid, challgrname, challgdname, matchfinder) VALUES ( '$ladderid','{$player1['team']}','{$player2['team']}','{$playerd['name']}','{$player2d['name']}','1')"); // $challenge_id=mysql_query("SELECT challid FROM challenges WHERE challgrname='$playerd[name]' AND challgdname='$player2d[name]'"); // $challenge_id=mysql_fetch_array($challenge_id); // mysql_query("INSERT INTO chall_chat (chall_id,challenger,challenged,type) // VALUES('$challenge_id[challid]','$player1[team]','$player2[team]','1')"); // mysql_query("DELETE FROM leagueplayers WHERE id='$player1[id]'"); //mysql_query("DELETE FROM leagueplayers WHERE id='$player2[id]'"); } } } } But the problem is it creates two rows in challenges when it should only create one. The zero on the first one should be the 405 and the first blank should be Gravy Boat and the second row shouldnt exist.... 12107 54 0 407 (Blank) bling bling 2010-07-15 04:14:25 1 12108 54 0 405 (Blank) Gravy Boat 2010-07-15 04:14:25 1
  10. So player1 doesnt pull any info here: if($timenow1 == $timenow5 && $timenow2 >= $timenow6){ mysql_query("UPDATE leagues SET status='0' WHERE id='$id'"); $update = mysql_query("SELECT * FROM leagueplayers WHERE league='$id'"); while ($player1 = mysql_fetch_array($update) && $player2 = mysql_fetch_array($update)) { echo $player1[id]; echo"-"; echo $player2[id]; } }
  11. Insert another row with data from two rows, of the loop. What I posted almost works and is what I want but the first row doesnt seem to be working while the second row does. Its been a while since I've used PHP so i'm a bit rusty sorry
  12. No, the first update was working fine, player1[id] just wasnt displaying 4 like it should have.
  13. hmm so I have this: if($timenow1 == $timenow5 && $timenow2 >= $timenow6){ mysql_query("UPDATE leagues SET status='0' WHERE id='$id'"); $update = mysql_query("SELECT * FROM leagueplayers WHERE league='$id'"); while ($player1 = mysql_fetch_array($update) && $player2 = mysql_fetch_array($update)) { echo $player1[id]; echo"-"; echo $player2[id]; } } And i got -5, the first ones not pulling anything...hmm
  14. I believe this will work great thank you so much.
  15. Well, I cant insert them as pairs as it's a list of people joining at different times, but i want to pull two players at a time from the tables run an insert using details from both, then delete both once the match is created since its basically a waiting list. I'm just not sure how to deal with two rows at a time in a loop.
  16. I have a loop that I need to pull two rows. I'm really confused Basically i have a table with a ton of players and i have a loop to match them up, i need to be able to have a loop match two rows then insert and delete. Heres what I got now that just has a normal loop. if($timenow1 == $timenow5 && $timenow2 >= $timenow6){ mysql_query("UPDATE leagues SET status='1' WHERE id='$id'"); $update = mysql_query("SELECT * FROM leagueplayers WHERE league='$id' ORDER BY "); while ($row = mysql_fetch_array($update)) { //Insert //Delete } } } Thank you
  17. Like this. if($_GET['mode'] == "showall"){ $qvar=""; }else{ $qvar="WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month' && year = '$year' or sender_id = {$ibforums->member["id"]} && month = '$month' && year = '$year' order by date_time DESC"; } $DB->query("SELECT * FROM ibf_logs $qvar"); OR if($_GET['mode'] == "showall"){ $DB->query("SELECT * FROM ibf_logs"); }else{ $DB->query("SELECT * FROM ibf_logs WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month' && year = '$year' or sender_id = {$ibforums->member["id"]} && month = '$month' && year = '$year' order by date_time DESC"); } yourfile.php?mode=showall would show all. This is a really simple thing i suggest reading more tutorials instead of jumping the gun and posting here.
  18. Something like this should work. $results = mysql_query(" SELECT ath_id_no, name, gender, photo, country, flag, sport, COUNT(ath_id) FROM athlete JOIN vote ON athlete.ath_id_no= vote.ath_id AND sport='$_POST[filter_sport]' GROUP BY ath_id "); if (mysql_num_rows($result)){ while($row=mysql_fetch_array($results)){ echo "<td>" . $row['name'] . "</td>"; } }else{ echo 'No results were found.'; }
  19. Hmmmm MySQL query failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #10' at line 1 : From what i found on that error it seems to be because the query is called by mysql_query and not fetch.
  20. Thanks..lol. It worked fine through that. Edit, actually no it doesn't it failed. Hmmm if it fails here, why would it work in phpmyadmin direct copy/paste 0.o
  21. Sorry, i misread it. You would need to call the page at the right time. Check the link above.
  22. Yes. Or you can use $_SERVER['REQUEST_TIME']. The only problem with this that i just thought of is someone would have to load that page right on that millisecond to run that statement, i think the cron job would be a better alternative. Read: http://www.modwest.com/help/kb5-125.html
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.