Jump to content

Recommended Posts

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/173381-solved-mysql-querries/
Share on other sites

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.