0

The below code only returning the second echo and if I remove && $fetch_desc = mysql_fetch_array($select_desc) then first echo is working else only second echo is displaying.

Any clue how to handle this? Thanks.

$select_name = mysql_query("query1");
$select_desc = mysql_query("query2");
      while($fetch_name = mysql_fetch_array($select_name) && $fetch_desc = mysql_fetch_array($select_desc)){
      echo $fetch_name['field_value'];
      echo $fetch_desc['field_value'];
      }
5
  • You may want to reconsider your question title Commented Jun 24, 2014 at 15:27
  • You should probably provide more details in the code snippet, such as the query. Provide a table structure perhaps as well... This sounds like something you should be either (A) querying multiple columns, or (B) using a JOIN.. Nonetheless, you shouldn't be using any mysql_* functions as they are deprecated. Commented Jun 24, 2014 at 15:28
  • Probably a boolean short-circuit biting you in the rump. If the entire while() condition can be determined by only executing ONE of the fetch operations, then the other fetch won't be performed. Commented Jun 24, 2014 at 15:29
  • What @HalfCrazed said, mysqli provides better security from SQL injections through pre-initialised queries! Commented Jun 24, 2014 at 15:30
  • Crikey, do people still use mysql_* functions these days? Commented Oct 2, 2015 at 11:44

1 Answer 1

3

Try:

while(($fetch_name = mysql_fetch_array($select_name)) && ($fetch_desc = mysql_fetch_array($select_desc))){

It might be that it's getting the conditions muddled, parenthesis stop that from happening.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.