sp@rky13 Posted September 7, 2009 Share Posted September 7, 2009 Ok, so I've worked on this off and on in the posts you can see that I've posted. I finally got back to it. Anyway so this is the idea I started with: <?php $con = mysql_connect("localhost","******","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("wwwspark_tribalwars", $con); $result = mysql_query("SELECT * FROM players_en28 WHERE name = '$vpt_sub'"); while($row = mysql_fetch_array($result)) { $id = $row['id']; } $result2 = mysql_query("SELECT * FROM villages_en28 WHERE player = '".$id."'"); while($row2 = mysql_fetch_array($result2)) { echo $row2['x']."|".$row2['y']." "; } mysql_close($con); ?> and then I was told to try this: <?php $con = mysql_connect("localhost","*******","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("wwwspark_tribalwars", $con); $result = mysql_query("SELECT GROUP_CONCAT(CONCAT_WS('|',b.x,b.y) SEPARATOR ' ') AS xy FROM players_en28 a INNER JOIN villages_en28 b ON a.id = b.player WHERE a.name = '$vpt_sub' GROUP BY a.id"); while($row = mysql_fetch_array($result)) { echo $row['xy']; } mysql_close($con); ?> I was able to customize the original to how I wanted but not the second. What I did with the original was this: <?php $con = mysql_connect("localhost","*****","********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("wwwspark_tribalwars", $con); $result = mysql_query("SELECT * FROM players_en28 WHERE name = '$vpt_sub'"); while($row = mysql_fetch_array($result)) { $id = $row['id']; } $result2 = mysql_query("SELECT * FROM villages_en28 WHERE player = '".$id."'[b] AND x BETWEEN $x1 AND $x2 AND y BETWEEN $y1 AND $y2[/b]"); while($row2 = mysql_fetch_array($result2)) { echo $row2['x']."|".$row2['y']." "; } mysql_close($con); ?> How can I do this in a code similar to the concat one? I also need to do that all with one like this: <?php $con = mysql_connect("localhost","*******","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("wwwspark_tribalwars", $con); $result = mysql_query("SELECT * FROM ally_en28 WHERE tag = '$vpt_sub'"); while($row = mysql_fetch_array($result)) { $id = $row['id']; $result2 = mysql_query("SELECT * FROM players_en28 WHERE ally = '".$id."'"); while($row2 = mysql_fetch_array($result2)) { $id2 = $row2['id']; $result3 = mysql_query("SELECT * FROM villages_en28 WHERE player = '".$id2."'"); while($row3 = mysql_fetch_array($result3)) { echo $row3['x']."|".$row3['y']." "; } } } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/ Share on other sites More sharing options...
anatak Posted September 7, 2009 Share Posted September 7, 2009 I am sorry I really cann't answer your problem but I don't think it is wise to post your db connection details online. Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-913963 Share on other sites More sharing options...
sp@rky13 Posted September 7, 2009 Author Share Posted September 7, 2009 Why can't I edit my post. So stupid. Time to change the password and sch. It only gives access, not editing for that pass. Mod please edit the post for me ASAP. EDIT: So I can edit this but not the other. So stupid Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-913981 Share on other sites More sharing options...
kickstart Posted September 7, 2009 Share Posted September 7, 2009 Hi You should be able to just put the check for x and y within the WHERE clause. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-914035 Share on other sites More sharing options...
sp@rky13 Posted September 7, 2009 Author Share Posted September 7, 2009 Dude, I'm stupid. Thank you. I will try that tomorrow No more Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-914091 Share on other sites More sharing options...
anatak Posted September 7, 2009 Share Posted September 7, 2009 hey Sparky you can only edit your post for a certain time. Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-914159 Share on other sites More sharing options...
sp@rky13 Posted September 7, 2009 Author Share Posted September 7, 2009 Yah, I found that out afterwards. Why???? I now have had that password up for 12 hours and I can't get rid of it Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-914354 Share on other sites More sharing options...
sp@rky13 Posted September 8, 2009 Author Share Posted September 8, 2009 Ok, so I've used that and it works fine. There is one more thing I'd like to do though. Is there a way I can as such rap this around the result. So instead of outputting this: 410|662 it would output this: [village]410|662[/village] I've looked through the code but have only found the thing for the middle ("|") and then the seperator. How can I add this in for this code: <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("wwwspark_tribalwars", $con); $result = mysql_query("SELECT GROUP_CONCAT(CONCAT_WS('|',b.x,b.y) SEPARATOR ' ') AS xy FROM players_en28 a INNER JOIN villages_en28 b ON a.id = b.player WHERE a.name = 'vpt_sub' AND x BETWEEN 0 AND 999 AND y BETWEEN 0 AND 999 GROUP BY a.id"); while($row = mysql_fetch_array($result)) { echo $row['xy']; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-914525 Share on other sites More sharing options...
kickstart Posted September 8, 2009 Share Posted September 8, 2009 Hi In the SQL or the PHP? In PHP it is easy:- while($row = mysql_fetch_array($result)) { echo '[village]'.$row['xy'].'[/village]'; } All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-914664 Share on other sites More sharing options...
sp@rky13 Posted September 8, 2009 Author Share Posted September 8, 2009 I really don't understand why I don't see these things. It's so obvious. sorry for wasting your time. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/#findComment-915055 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.