Request to database:

$result = database_select("SELECT p.type_condition AS pay, o.type_condition AS orders, n.type_condition AS news, a.type_condition AS other, s.index AS index, s.login AS login, s.telephone AS telephone FROM `vixen_erps_services_sms` s LEFT JOIN `vixen_erps_services_type` p ON p.type_id = s.pay LEFT JOIN `vixen_erps_services_type` o ON o.type_id = s.orders LEFT JOIN `vixen_erps_services_type` n ON n.type_id = s.news LEFT JOIN `vixen_erps_services_type` a ON a.type_id = s.other"); $col = database_numrows($result); 

Functions:

 function database_select($select_text){ $query = "$select_text"; $result = mysql_query($query); return $result; } function database_numrows($result){ $numrows = mysql_numrows($result); return $numrows; } 

Throws out Warning: mysql_numrows (): supplied result resource .

If I remove the index field from the sample, then everything works fine. But I need to choose the index too. I do not understand what the problem is. All fields in the database tables exist.

  • You can ask, what is the meaning of the database_select () function? - Ipatiev
  • To write one word database_select instead of two lines of code. If you use a non-function - the problem does not disappear. - luckydutch
  • A why here to write two lines of code? Why can't I write one - $result = mysql_query("SELECT p.type_condition... ? - Ipatyev
  • The bottom line is that it does not work regardless of how the request is processed. - luckydutch
  • What doesn't work is understandable. I'm interested in the meaning of the database_select () function. The "word" mysql_query is even shorter. Where do two lines come from? - Ipatiev

1 answer 1

  1. change the database_select () function to

     function database_select($query){ return mysql_query($query) or trigger_error(mysql_error()); } 
  2. Take the index in backquotes, like this:

     `index` 
  • Query was empty - luckydutch
  • Why can the request be empty? I do not understand. All fields in the table are, the data in them too. The request is written correctly. - luckydutch
  • Because I did not finish the variable in the function first, but then I fixed it. We need to take a new version - Ipatiev
  • So it's not a variable, I don’t even use the function at all. The result is the same. query is empty. Moreover, even regardless of whether I select the index field or not. - luckydutch
  • The point is in the variable. An empty request means that the request was empty. That is, no request was passed to the function. - Ipatiev