Bonjour,
J’ai un gros problème je n’y arrive pas voici mon code :
$id2=$_GET'id'];
$sql = mysql_query ("SELECT id_vo FROM uscars WHERE uscars.modele LIKE '%$marque%' ORDER BY prix_public ASC");
while(($row] = mysql_fetch_assoc($sql)) || array_pop($row)); {
print_r($row);
}
Resultat de la requête quand je fais un print_r :
Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) [11] => Array ( [id_vo] => 120 ) [12] => Array ( [id_vo] => 270 ) [13] => Array ( [id_vo] => 288 ) [14] => Array ( [id_vo] => 228 ) )
Je dois trouver l’id suivant du resultat de la requete ci-dessus. Par exemple je suis à l’enregistrement id_vo 292 (292 est récupérer par un GET $id2) et je voudrais afficher dans une url l’id_vo 15.
J’ai été voir la doc des tableaux mais a chaque fois que j’essaye une fonction cela me retourne array
Quelqu’un peut m’aider
merci
pour rechercher dans ton premier tableau tu peux faire ceci :
$key = array_search(array("id_vo" => $id2), $tonTableau);
$key = $key + 1;
$id = $tonTableau$key]"id_vo"];
echo "---".$id."---";
$tonTableau étant la variable contenant le tableau.
Pour le soucis du grand tableau quand tu enlève le ";".
Cela vient du array_pop().
Il ne doit pas y avoir de ";".
De rien ;)
Tu peux essayer ça dans ta boucle :
if($row'id_vo'] == $id2){
$suivant = true;
}
if($row'id_vo'] != $id2 && $suivant == true){
$id3 = $row'id_vo']; // Tu récupère ton item suivant
$suivant = false;
}
dans ta boucle while, il faut écrire $row et pas $row]
bonjour snollito,
tout d'abord merci de ta réponse rapide, j'ai essayé l'exemple que tu m'as fait mais cela ne marche pas.
si j'enlève les crochets dans ma boucle while cela n'affiche plus rien.
Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) [11] => Array ( [id_vo] => 120 ) [12] => Array ( [id_vo] => 270 ) [13] => Array ( [id_vo] => 288 ) [14] => Array ( [id_vo] => 228 ) )
je voudrai faire une recherche dans le tableau ci dessus exemple : l'id_vo 292 puis chercher la clé suivante [2] pour afficher dans une url id_vo 15
donc il faudrait prendre clé actuelle [1] + 1 puis afficher l'id_vo de la clé [2]
mais je n'y arrive pas :)
quand je l'enlève j'ai le double de résultat
Array ( [0] => Array ( [id_vo] => 231 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) [11] => Array ( [id_vo] => 120 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) [11] => Array ( [id_vo] => 120 ) [12] => Array ( [id_vo] => 270 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) [11] => Array ( [id_vo] => 120 ) [12] => Array ( [id_vo] => 270 ) [13] => Array ( [id_vo] => 288 ) ) Array ( [0] => Array ( [id_vo] => 231 ) [1] => Array ( [id_vo] => 292 ) [2] => Array ( [id_vo] => 15 ) [3] => Array ( [id_vo] => 226 ) [4] => Array ( [id_vo] => 111 ) [5] => Array ( [id_vo] => 13 ) [6] => Array ( [id_vo] => 291 ) [7] => Array ( [id_vo] => 144 ) [8] => Array ( [id_vo] => 207 ) [9] => Array ( [id_vo] => 181 ) [10] => Array ( [id_vo] => 178 ) [11] => Array ( [id_vo] => 120 ) [12] => Array ( [id_vo] => 270 ) [13] => Array ( [id_vo] => 288 ) [14] => Array ( [id_vo] => 228 ) )