Reputation: 213
Im having problem. I just connected to db and selected column and added it to array but, when i try to use command array_unique i get error that it is tring. What am i doing wrong here, cant uderstand, because it is array. Here is my code, hope you will help me:
<?php
$array1 = array();
$query1 = mysql_query("SELECT ticket_company FROM {$dbprefix}tickets");
while ($row = mysql_fetch_assoc($query1)) {
$array1 = $row['ticket_company'];
echo "$array1\n";
}
$array1 = array_unique($array1);
echo "<pre>";
print_r($array1);
echo "</pre>";
And here is what prints
echo "$array1\n";
this one:<br>
25 25 25 25 25 25 25 0 0 0 1 0 0 25 25 0 0 25 0 25 0 25 1 0 0 0 0 0 29
0 0 25 1 0 1 0 0 0 0 25 0 0 25 0 25 0 25 0 0 0 0 25 0 25 25 0 0 1 25 0
0 36 0 25 0 0 0 25 0 25 25 0 0 25 0 0 24 0 0 0 0 0 0 24 0 0 25 0 25 1
42 42 0 1 1 7 0 0 0 <br>
And the error:
Warning: array_unique() expects parameter 1 to be array, string given in
Upvotes: 0
Views: 53
Reputation: 20469
$array = $row['ticket_company'];
$row['ticked_company']
is clearly a string, sql databases dont have array columns. Perhaps you mean to add to the array;
$array[] = $row['ticket_company']; //note square brackets
//or if you prefer the verbosity
array_push($array, $row['ticket_company']);
Upvotes: 1