Foreach fonksiyonu kullanarak Biçimlendirme dizi çıktısı

0 Cevap php

O, benim sql tablodaki bir alan "Kimliği" veri toplamak bir diziye tüm verileri göndermek ve daha sonra dizideki whats bir değişkeni karşılaştırmak gerekiyordu şöyle bir komut dosyası var. Değişkenin değerini dizide zaten varsa, bu değer geçersiz olduğunu kullanıcı söyle.

$sql = "SELECT *" //User info
    . " FROM Users" ;
$result = mysql_query($sql); 
//insert where line for assessorid


$users = array();

while(($user = mysql_fetch_assoc($result))) { 
$users[] = $user;
}

foreach($users as $user){ 
$user['UserID']; 
 }

I need the output of $users to be equivalent to array('user1','user2','user3'); Whats happening is data comes in from a form as $user_name. I want to use this in a statement like follows:

if(in_array($user_name,$users)){
  echo "username available"
}
else{
  echo "not available"}

I tried using the extract function, but that just created a big mess. Im not sure what is incorrect about what I'm doing, unless the format of $users as an array cannot be parsed in the in_array() function as it is formatted currently. Any advice is much appreciated. Thanks!

0 Cevap