K
K
Konstantin B.2014-06-07 20:43:18
MySQL
Konstantin B., 2014-06-07 20:43:18

Output from database to array

There is a table with records, it is necessary to display data from it only from one column and present it as an array from

$r=$mysqli->query("SELECT company_URL_name FROM company");
//в массив вида
$arr=array('AUDI', 'BMW', 'NISSAN', 'TOYOTA');
//чтобы работала проверка вида
if((in_array($_GET['n1'], $arr))){
}

I will be grateful for the help
now I have output like this
$r=$mysqli->query("SELECT company_URL_name FROM company");
  $urls=array();
   while($row=mysqli_fetch_array($r)){
    $urls[] = $row['company_URL_name'];
  }
        if((in_array($_GET['n1'], $urls))){
        echo $urls;
  }
    else{
        echo 'Введеня вами страница не существует';
    }

It seems that the array is created correctly, and the check passes, but how to enter the current link?
as echo $urls; or substitute it as the name of the controller?
echo $urls; displays an array, but is it necessary that if the link is AUDI, then AUDI is displayed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Starchenko, 2014-07-13
@Starche

Use array_search

$key=array_search($_GET['n1'], $urls);
if($key!==false){
    echo $urls[$key];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question