0

heres my code.

$speakers=array();
    $handler2=mysql_query("SELECT fName,lName,title FROM speaker ;");
        while($row = mysql_fetch_assoc($handler2)){
        $speakers[] =$row['fName'],$row['lName'],$row['title'];
        }

i want to get fName,lName and title from my database and store it in a single array index.

so print_r($speakers)'

will output the value of fName,lName,title like this

Array ([0]=>fname lname title [1]=>fname lname title).

can you guys help?

1

3 Answers 3

0

If you want to save field values as a string( [0]=>fname lname title) - change your code as shown below:

while ($row = mysql_fetch_assoc($handler2)) {
    $speakers[] = $row['fName']. " " .$row['lName']. " " .$row['title'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks man, this is exactly what i need. wew,didnt know it was that simple, maybe my cold affected the way i think..haha thanks @RomanPerekhrerst
0

you can do this easily:

while($row = mysql_fetch_assoc($handler2)){
    $speakers[] =array($row['fName'],$row['lName'],$row['title']);
}

2 Comments

thanks, but this will create multiple indexes. not exactly what i had in mind but no worries,i found an answer.
the guy who answered after you,, while ($row = mysql_fetch_assoc($handler2)) { $speakers[] = $row['fName']. " " .$row['lName']. " " .$row['title']; }
0

Depending on your context you could also make MySQL do the job for you:

SELECT CONCAT_WS(' ', title, fName, lName) as spkr FROM speaker;

This will only return one column, spkr, with the values already concatenated. See CONCAT_WS.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.