How to show only one entry from the array.

$response = file_get_contents("http://api.vk.com/method/likes.getList?type=".$myrow["type"]."&owner_id=".$myrow["owner_id"]."&item_id=".$myrow["item_id"]."&filter=likes"); $resp = json_decode($response, true); if (!in_array($check_like, $resp['response']['users'])) { echo $myrow["id"]; } 

How to show $myrow["id"]; only once?

Here is the entire code:

 $result = mysql_query( "SELECT * FROM vk_likes WHERE sex='0' AND country='0' AND user_age_from='0' AND user_age_to='100' AND (need_likes>there_likes) AND order_user_uid!='$check_like' "); $myrow = mysql_fetch_array($result); do { $response = file_get_contents("http://api.vk.com/method/likes.getList?type=".$myrow["type"]."&owner_id=".$myrow["owner_id"]."&item_id=".$myrow["item_id"]."&filter=likes"); $resp = json_decode($response, true); if (!in_array($check_like, $resp['response']['users'])) { echo $myrow["id"]; } } while($myrow = mysql_fetch_array($result)); 
  • In your code, it is displayed 1 time. - LEQADA
  • @LEQADA is not much, but I need only the first result. - Anatoly
  • In the course of executing the code, 1,2,3,4,5 is displayed, and only that the first result 1 is output - Anatoly
  • one
    @ Anatoly in the if block, then it is necessary to write break; In general, if you have a large list, and the value is at the end, contact you will be banned for frequent access to the API - Alexei Shimansky
  • @ Alexey Shimansky This is what I am authorizing through the link, the user inserts the link into the form, I get the screen_name from it, then I suggest that he like it, the links for the like are selected from the base, and by the method like.getList I check that the user’s marks are still not there, then the link selected from the base already has a mark, I don’t show it, and if not, then I’ll show it, then the person puts the like and the script checks if it’s delivered if yes I get the rest of the information about the users and then I register or authorize the user. And how to reduce inquiries to api itself thought - Anatoly

1 answer 1

Redo the loop so that it is interrupted after finding $ myrow ['id]. For example:

  $result = mysql_query("SELECT * FROM vk_likes WHERE sex='0' AND country='0' AND user_age_from='0' AND user_age_to='100' AND (need_likes>there_likes) AND order_user_uid!='$check_like' "); $do = true; while($do && $myrow = mysql_fetch_array($result)) { $response = file_get_contents("http://api.vk.com/method/likes.getList?type=".$myrow["type"]."&owner_id=".$myrow["owner_id"]."&item_id=".$myrow["item_id"]."&filter=likes"); $resp = json_decode($response, true); if (!in_array($check_like, $resp['response']['users'])) { echo $myrow["id"]; $do = false; }; } 
  • I think instead of $do = false; you can safely enter break; but in general I would remake everything under PDO - fonjeekay