Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A first glimpse of your code:</p> <pre><code>while($row = mysql_fetch_array( $res, $res2 )) { </code></pre> <p>isn't correct because $res2 SHOULD be a resulttype and not a result from a query.</p> <p>The options are:</p> <pre><code>while($row = mysql_fetch_array( $res, MYSQL_ASSOC )) { while($row = mysql_fetch_array( $res, MYSQL_NUM )) { while($row = mysql_fetch_array( $res, MYSQL_BOTH )) { </code></pre> <p>I guess you're trying to achieve something like this:</p> <pre><code>$res = mysql_query("SELECT * FROM my_table WHERE (x BETWEEN $x -75 AND $x +75) AND (y BETWEEN $y -75 AND $y +75) AND dip LIKE '%$term%'"); </code></pre> <p>This would mean code like this:</p> <pre><code>&lt;?php $x = $_POST['x']; $y = $_POST['y']; $term = $_POST['term']; mysql_connect ("localhost","host","pass") or die (mysql_error()); mysql_select_db ("d_base"); $res = mysql_query("SELECT * FROM my_table WHERE (x BETWEEN $x -75 AND $x +75) AND (y BETWEEN $y -75 AND $y +75) AND dip LIKE '%$term%'"); echo "&lt;table border='1' align='center' cellpadding='5'&gt;"; echo "&lt;tr&gt; &lt;th&gt;City Name&lt;/th&gt; &lt;th&gt;X&lt;/th&gt; &lt;th&gt;Y&lt;/th&gt; &lt;th&gt;Diplomacy&lt;/th&gt; &lt;/tr&gt;"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $res, MYSQL_ASSOC )) { // echo out the contents of each row into a table echo '&lt;td&gt;' . $row['city'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['x'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['y'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['dip'] . '&lt;/td&gt;'; echo "&lt;/tr&gt;"; // close table&gt; echo "&lt;/table&gt;"; } ?&gt; </code></pre> <p>For a better database, I think you SHOULD store the terms in a separate table and do some joining instead:</p> <p>If you decide to do this, use a query in a way similar to this:</p> <pre><code> $res = mysql_query("SELECT * FROM my_table mt LEFT JOIN terms t ON (mt.term_id = t.id) WHERE (x BETWEEN $x -75 AND $x +75) AND (y BETWEEN $y -75 AND $y +75) AND dip LIKE '%$term%'"); </code></pre> <p>Another tip is to use PDO. It really isn't harder then using mysql_* - functions. In a way it's easier to create better and more readable code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload