Jump to content

[SOLVED] Returning Column Name as Variable


Fruct0se

Recommended Posts

This always works fine except for some reason when using the LIKE statement. I am trying to return a group of rows and call them out by their column names. So if I have a column called NAME then when extracting the row I normally can reference that result by echoing $NAME, when using the like statement it is returning 0 and 1 etc... for the column names, any ideas?

<?php
$result = mysql_query("Select * from images where NAME like '$search%'"); 
while($i = mysql_fetch_row($result)){
    //This for each will echo:  0 NAMEofIMAGE
    foreach ($i as $name=>$val) {
    echo "$name is a $val <BR/>";
}
       //This will echo nothing for the $NAME because the query is not returning the column names
extract($i);
echo "<b>Name: ".$NAME."</b><br/>";
}
?>

 

Like I said, without the LIKE statement the column names are returned and when extracted can be used. Thanks for the help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.