I am confused as to why my query is not returning all the data. I have a table departments which has 3 fields, id,code,name. For some reason, the query is returning the data from the name field apart from if an entry in the code field is also present in the name field. So, if the code = demo it will return all data for the code ‘demo’ apart from the ‘demo’ in the name field.
I am wondering if it is something to do with the distinct statement? If I run this query directly in phpMyAdmin, it returns all data correctly. I would be grateful if someone could point out my error.
Well allow me to say that if you’re running the same query in phpMyAdmin and in PHP, and getting different results, the problem isn’t your query.
Are you absolutely sure that the PHP script is connecting to the same database? Not running a local copy by accident or something?
Also your echo line should be putting braces around the variables, if you’re trying to use array references. Also, you’ve not put the <option>'s inside a select.
I am using the chosen jquery plugin for my selects. This is the code I am using in my html.
<select class="chosen-select" id="dept" name="dept" data-placeholder="No data to display" disabled>
<option value=""></option>
</select>
The blank option is for the data-placeholder. I am running on localhost in wamp and connecting to the correct database. Sorry I don’t understand your comment
I get 5 but it is only showing 4 in the select and in the resource tab of console. It seems to be leaving out the variable value which is value in the code field. In this case demo.