Jump to content

[SOLVED] Returning Column Name as Variable


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.