Hello, I am currently facing a problem with a query of mine. You see, it wastes to much resources. I have an idea of how to fix it, but I just don't know how to implement it.
I have a table named Test with 4 columns. X, Y, Z, textimage. The table has a whole bunch of rows with x, y, z co ordinates with a text image. Is there another alternative than to have to query the database so many time to just get the table rows text image and to be scalable with x, y, z?
*EDIT* I have gotten up to this point,
What I need is 2 variables that will auto increment as the query runs.
But I just can't seem to get it right. For some reason, the above statement doesn't work as intended for me. Is there an easier way to do this?
I have a table named Test with 4 columns. X, Y, Z, textimage. The table has a whole bunch of rows with x, y, z co ordinates with a text image. Is there another alternative than to have to query the database so many time to just get the table rows text image and to be scalable with x, y, z?
PHP:
$sql = mysql_fetch_array(mysql_query("SELECT * FROM Test WHERE X='1' AND Y='1' AND Z='1'"));
for ($y=$sql['Y'];$y<=65;$y++)
{
for ($x=$sql['X'];$x<=100;$x++)
{
$query = mysql_fetch_array(mysql_query("SELECT * FROM Test WHERE X='{$x}' AND Y='{$y}' AND Z='{$sql['Z']}'"));
echo $query['textimage'];
}
echo '<br/>';
}
*EDIT* I have gotten up to this point,
PHP:
$query = mysql_query("SELECT * FROM Test WHERE (X BETWEEN 1 AND 100) AND (Y BETWEEN 1 AND 65) AND Z='1' ORDER BY Y, X");
$y=1;
while ($row = mysql_fetch_array($query))
{
if ($row['Y'] == $y)
{
echo $row['Image'];
} else {
echo '<br/>';
$y++;
}
}
What I need is 2 variables that will auto increment as the query runs.
PHP:
$query = mysql_query("SELECT * FROM Test WHERE (X BETWEEN 1 AND 100) AND (Y BETWEEN 1 AND 65) AND Z='1' ORDER BY Y, X");
$y=1;
//auto increment variables
$yi = 0;
$xi = 0;
while ($row = mysql_fetch_array($query))
{
if ($row['Y'] == $y)
{
echo $row['Image'];
$xi++;
} else {
echo '<br/>';
$y++;
$yi++;
}
}
But I just can't seem to get it right. For some reason, the above statement doesn't work as intended for me. Is there an easier way to do this?
Last edited: