0

i have a string like

 $email= "[email protected],[email protected],[email protected]";

first i explode this like

 $wordChunks = explode(",", $email);
for($i = 0; $i < count($wordChunks); $i++){

$eex = mysqli_query($database->connection,"SELECT * FROM contacts where email =   '$wordChunks[$i]' and owner = '$session->username'") or die(mysqli_error());
    while($zzz = mysqli_fetch_array($eex)){


     if(empty($zzz['bedrijfsnaam'])){
        $aa = "<font size='2'>".ucfirst($zzz['name'])." ".ucfirst($zzz['lastname'])."</font>";
    }else{
     $aa = "<font size='2'>".ucfirst($zzz['bedrijfsnaam'])."</font>";
    }
    echo $aa;

     }
}

The question is how can i order $aa in alphabetic order

What i tried is

$array = str_split($aa, 1);
sort($array);
foreach ($array as $val) {
echo $val."<br>";
}

But this orders only the string in $aa; example string = hellow output is ehllow. but i want order the output of $aa in the while loop

3
  • 1
    You can ORDER BY in your SQL statement, if I understand you right. Commented Dec 19, 2013 at 13:11
  • 1
    Order is not needed becouse the db output is a single output per email Commented Dec 19, 2013 at 14:21
  • did you find how to do this? Commented Jul 4, 2014 at 17:44

2 Answers 2

1

No need to use explode() and than loop it. Just put that string in query and it will work.Change your query to use IN() for searching emails and do order by so that you will get the data in ascending order itself. you can try like this:

$eex = mysqli_query($database->connection,"SELECT * FROM contacts where email IN ($email) and owner = '$session->username' order by email") or die(mysqli_error());
    while($zzz = mysqli_fetch_array($eex)){


     if(empty($zzz['bedrijfsnaam'])){
        $aa = "<font size='2'>".ucfirst($zzz['name'])." ".ucfirst($zzz['lastname'])."</font>";
    }else{
     $aa = "<font size='2'>".ucfirst($zzz['bedrijfsnaam'])."</font>";
    }
    echo $aa;

     }
Sign up to request clarification or add additional context in comments.

1 Comment

This is not the answer what i am looking for. I must explode $email and use it to get the results in db for each email that is exploded. Each email adresses in $email is also in contacts row of my db with information what i need like name lastname...
0

Just Use

$aa = 'hellow';
$array = str_split($aa, 1);

foreach ($array as $val) {
echo $val."<br>";
}

Result:

h e l l o w

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.