Jump to content

PHP/MYSQL including php, not echo


sp@rky13

Recommended Posts

Hi

 

Can't see anything in that code fragment that would cause it.

 

However you also seem to have removed the GROUP_CONCAT, and I think with that before you would have returned a single row with all of them joined together while now you are looping through the results.

 

All the best

 

Keith

Link to comment
Share on other sites

I think you are looking for something like this

 

if i < 10 =>

echo x between 100*i and (100*i+99) and Y between 0 and 99

else

echo x between ((i/10 rest of division)*100 ) and ((i/10 rest of division)*100 +99 ) and y between (i/10 integer part of division)*100 +99 

 

so you need to find or write a function that return you

1 the rest of a division

2 the integer part of a division

 

I think there will be a function like that available in php I just don't know it

 

 

Link to comment
Share on other sites

 

Yes, but where is the rest of the code to generate that javascript?

 

The assumption in that post is that you would want some other data from the select, hence not using GROUP_CONCAT was more flexible.

 

All the best

 

Keith

Link to comment
Share on other sites

Hi

 

The code posted above just generates a list of X and Y coordinates. There is nothing in it at all to put out the javascript calls . My guess would be that the Javascript is  put out in a fixed format with a line break half way through and then the coordinates are echoed out, but that is just a guess. Without see where the rest of it comes from I cannot say anything useful about where the line break comes from.

 

For example my guess is you have code like this:-

 

<pre class="alt2" dir="ltr" style="
	margin: 0px;
	padding: 6px;
	border: 1px inset;
	width: 640px;
	height: 34px;
	text-align: left;
	background-color: #EFE6C9;
	overflow: auto">javascript:function%20end(){c='
<?php
$yLow = floor($k1 / 10) * 100;
$yHigh = $yLow + 99;

$xLow = ($k1 % 10) * 100;
$xHigh = $xLow + 99;
$BetweenClause = "x BETWEEN $xLow AND $xHigh AND y BETWEEN $yLow AND $yHigh";

$con = mysql_connect("localhost","*******","******");
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}

mysql_select_db("wwwspark_tribalwars", $con);

$result = mysql_query("SELECT c.player AS playerid, CONCAT_WS('|',c.x,c.y) AS xy FROM ally_en28 a INNER JOIN players_en28 b ON a.id = b.ally INNER JOIN villages_en28 c ON b.id = c.player WHERE a.tag = '$vpt_sub' AND $BetweenClause ORDER BY c.player") or die(mysql_error());

while($row = mysql_fetch_array($result))
{
echo $row['xy']." "; 
}
mysql_close($con);
?>';var%20d=document;if(window.frames.length>0)d=window.main.document;url=d.URL;if(url.indexOf('screen=place')==-1)alert('This%20script%20needs%20to%20be%20run%20from%20the%20rally%20point');a=c.match(/(\d+\|\d+)/g);b=a[Math.round(Math.random()*(a.length-1))].split("|").forms[0].x.value=b[0].forms[0].y.value=b[1].forms[0].spear.value=0;d.forms[0].sword.value=0;d.forms[0].axe.value=0;d.forms[0].spy.value=0;d.forms[0].light.value=0;d.forms[0].heavy.value=0;d.forms[0].ram.value=0;d.forms[0].catapult.value=0;d.forms[0].snob.value=0;d.forms[0].archer.value=0;d.forms[0].marcher.value=0;d.forms[0].knight.value=0;}end();</pre>

 

whereas you want something subtly different like this.

 

<pre class="alt2" dir="ltr" style="
	margin: 0px;
	padding: 6px;
	border: 1px inset;
	width: 640px;
	height: 34px;
	text-align: left;
	background-color: #EFE6C9;
	overflow: auto">javascript:function%20end(){c='<?php
$yLow = floor($k1 / 10) * 100;
$yHigh = $yLow + 99;

$xLow = ($k1 % 10) * 100;
$xHigh = $xLow + 99;
$BetweenClause = "x BETWEEN $xLow AND $xHigh AND y BETWEEN $yLow AND $yHigh";
$con = mysql_connect("localhost","*******","******");
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}

mysql_select_db("wwwspark_tribalwars", $con);

$result = mysql_query("SELECT c.player AS playerid, CONCAT_WS('|',c.x,c.y) AS xy FROM ally_en28 a INNER JOIN players_en28 b ON a.id = b.ally INNER JOIN villages_en28 c ON b.id = c.player WHERE a.tag = '$vpt_sub' AND $BetweenClause ORDER BY c.player") or die(mysql_error());

while($row = mysql_fetch_array($result))
{
echo $row['xy']." "; 
}
mysql_close($con);
?>';var%20d=document;if(window.frames.length>0)d=window.main.document;url=d.URL;if(url.indexOf('screen=place')==-1)alert('This%20script%20needs%20to%20be%20run%20from%20the%20rally%20point');a=c.match(/(\d+\|\d+)/g);b=a[Math.round(Math.random()*(a.length-1))].split("|").forms[0].x.value=b[0].forms[0].y.value=b[1].forms[0].spear.value=0;d.forms[0].sword.value=0;d.forms[0].axe.value=0;d.forms[0].spy.value=0;d.forms[0].light.value=0;d.forms[0].heavy.value=0;d.forms[0].ram.value=0;d.forms[0].catapult.value=0;d.forms[0].snob.value=0;d.forms[0].archer.value=0;d.forms[0].marcher.value=0;d.forms[0].knight.value=0;}end();</pre>

 

However I would be tempted to just built up the list of coordinates and then echo them out once like this

 

<?php
$yLow = floor($k1 / 10) * 100;
$yHigh = $yLow + 99;

$xLow = ($k1 % 10) * 100;
$xHigh = $xLow + 99;
$BetweenClause = "x BETWEEN $xLow AND $xHigh AND y BETWEEN $yLow AND $yHigh";

$con = mysql_connect("localhost","*******","******");
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}

mysql_select_db("wwwspark_tribalwars", $con);

$result = mysql_query("SELECT c.player AS playerid, CONCAT_WS('|',c.x,c.y) AS xy FROM ally_en28 a INNER JOIN players_en28 b ON a.id = b.ally INNER JOIN villages_en28 c ON b.id = c.player WHERE a.tag = '$vpt_sub' AND $BetweenClause ORDER BY c.player") or die(mysql_error());

$CoOrdStr = "";

while($row = mysql_fetch_array($result))
{
$CoOrdStr .= $row['xy']." "; 
}
mysql_close($con);
?>
<pre class="alt2" dir="ltr" style="
	margin: 0px;
	padding: 6px;
	border: 1px inset;
	width: 640px;
	height: 34px;
	text-align: left;
	background-color: #EFE6C9;
	overflow: auto">javascript:function%20end(){c='<?php echo $CoOrdStr; ?>';var%20d=document;if(window.frames.length>0)d=window.main.document;url=d.URL;if(url.indexOf('screen=place')==-1)alert('This%20script%20needs%20to%20be%20run%20from%20the%20rally%20point');a=c.match(/(\d+\|\d+)/g);b=a[Math.round(Math.random()*(a.length-1))].split("|").forms[0].x.value=b[0].forms[0].y.value=b[1].forms[0].spear.value=0;d.forms[0].sword.value=0;d.forms[0].axe.value=0;d.forms[0].spy.value=0;d.forms[0].light.value=0;d.forms[0].heavy.value=0;d.forms[0].ram.value=0;d.forms[0].catapult.value=0;d.forms[0].snob.value=0;d.forms[0].archer.value=0;d.forms[0].marcher.value=0;d.forms[0].knight.value=0;}end();</pre>

 

All the best

 

Keith

Link to comment
Share on other sites

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.