1

I am running a query with a while loop that creates an array of the column names

while($ContactLookup_Row = mysql_fetch_array($ContactLookup_Rs)) {
        $ContactLookup_Results[] = array(
        'sequence'=>$ContactLookup_Row["sequence"], 
        'forename'=>$ContactLookup_Row["forename"],
        'surname'=>$ContactLookup_Row["surname"]
         );
    }

How can I make the loop add all the column names as their own variables without having to type them all out manually?

Should I put $ContactsLookup_Results[]= array( before the while loop. And then ); after the while loop

And then I'm not sure about within the loop?

I want it to look like:

'ColumnName'=>$ContactLookup_Row["ColumnName"]

With a , on the end of each one but not the last one

2
  • Obligatory: don't use mysql_ functions anymore. Commented Dec 31, 2013 at 12:05
  • Can you post how the resulting array should then look like? Becouse I don't know what you mean... Commented Dec 31, 2013 at 12:07

2 Answers 2

0

How about

while($ContactLookup_Row = mysql_fetch_array($ContactLookup_Rs)) {
        $ContactLookup_Results[] = $ContactLookup_Row;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.

$sql="DESCRIBE $_table_name";

$result=mysql_query($sql) or die(mysql_error());

while($data = mysql_fetch_assoc($result)){

    $columns[$data['Field']]=$data['Field'];

}

Comments

Your Answer

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