MySQL query only prints odd rows

I have the following PHP method that returns a JSON string from a MySQL query:

$sys_words_ref_join_query = mysql_query("
 SELECT user_words.*, sys_words.*
 FROM user_words, sys_words
 WHERE user_words.sys_words_ref = sys_words.sys_words_ref 
 & user_words.user_info_ref = '1'
 LIMIT 0, 7
");

$json_array = array();

while($words_obj = mysql_fetch_object($sys_words_ref_join_query)) {
 $json_array[] = $words_obj;
}

$result = json_encode($json_array);

echo $result;

The problem I ran into is that it $resultonly reflects odd DB rows, for example. 1,3,5 ... etc.

Any idea why? Thank.

+3
source share
4 answers

You should probably use Logical AND ( AND) instead of Bitwise AND ( &) in the where clause:

WHERE user_words.sys_words_ref = sys_words.sys_words_ref 
 AND user_words.user_info_ref = '1'
+8
source

This condition:

user_words.sys_words_ref = sys_words.sys_words_ref & user_words.user_info_ref = 1

implies bitwise ANDbetween sys_words.sys_words_refand user_words.user_info_ref, which is later compared withuser_words.sys_words_ref

, user_words.sys_words_ref, AND , , , ( ).

+1

Did you run the mysql_query function ? I do not see there. Also try repeating this:

print '<pre>';
print_r ($result);
0
source

Rows in a relational database do not have external ordering, and therefore do not have row numbers. RDBMS is free to use any internal order that the developer wishes. If you need an order, you must explicitly indicate it with ORDER BY.

0
source

Source: https://habr.com/ru/post/1731194/


All Articles