I'm retrieving data from the database that would be "The Indicator of the Indicated", but it catches all up to retrieve all. What I need to do is get only the first 3 results.
And if I tell you how many results I want to get, that is, set this in the function or in some variable and when I get the X value of the variable, then it stops searching because it does not have any more need.
Currently I have done this function, but it is returning all the right data, but it is returning more than 3 and I only want 3 for now. I need to get the top 3 only.
<?php
$db = mysql_connect('localhost', 'root', 'vertrigo');
$bd = mysql_select_db('cotas', $db);
$array = array();
function indicadores($id){
global $array;
$query = mysql_query("SELECT * FROM indicadores WHERE id_indicado = '$id'");
if(mysql_num_rows($query) > 0){
$fetch = mysql_fetch_object($query);
$id = $fetch->id_indicador;
$array[] = $id;
indicadores($id);
}
}
indicadores(10);
echo var_dump($array);
?>