Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this SQL query not work?
    text
    copied!<p>I have been bugging by head over this, but couldn't get this to work. What's wrong with this?</p> <pre><code> $query="Select studentid,firstname,lastname,pts from students where collegeid=4"; $result=mysql_query($query); $row=mysql_fetch_array($result); $pts=$row['pts']; $name=$row['firstname']." ".$row['lastname']; $rank= mysql_num_rows(queryMysql("Select distinct pts from students where pts&gt;=$pts")); echo&lt;&lt;&lt;_END &lt;a href="student_profile.php?studentid=$row[studentid]" style="text-decoration: none;"&gt; &lt;div class="apps_each your_rank"&gt; &lt;span style="margin-right:5px;"&gt;$rank&lt;/span&gt; &lt;div class="dp_small_c"&gt;&lt;img class="dp_small" src="upload/$row[studentid].jpg"/&gt;&lt;/div&gt; &lt;span class="apps_names"&gt;$name&lt;/span&gt; &lt;div style="float:right"&gt; &lt;img src='pts.png' /&gt;&lt;span&gt;$row[pts]&lt;/span&gt; &lt;img src='level.png' /&gt;&lt;span&gt;Level 1&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/a&gt; </code></pre> <p>_END;</p> <p>The error:</p> <blockquote> <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.</p> </blockquote> <p>Surprisingly, below one(removing the WHERE clause) works. Why?</p> <pre><code>$row=mysql_fetch_array(mysql_query("Select studentid,pts,firstname,lastname from students")); </code></pre> <p>Table structure:</p> <p>Everything's fine with table and its columns, because this query works everywhere else, only not here!</p>
 

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