alarik149 Posted March 8, 2006 Share Posted March 8, 2006 hi all you guru PHP&MySQL people.I want you to help me with something.So I have a database named championships and in it I have 5 fields with names '1''2''3''4''5'.I want the variable $a to hold the name of the field '1',how do I do that?pls tell me.thank you in advance:) Quote Link to comment https://forums.phpfreaks.com/topic/4453-field-name-into-a-variable/ Share on other sites More sharing options...
alarik149 Posted March 8, 2006 Author Share Posted March 8, 2006 or tell me how do i detect the name of a field that contains a certain text.for example how do I get the name of the field that holds litter "abcdef". Quote Link to comment https://forums.phpfreaks.com/topic/4453-field-name-into-a-variable/#findComment-15456 Share on other sites More sharing options...
kenrbnsn Posted March 8, 2006 Share Posted March 8, 2006 Try this:[code]<?php$q = "select * from tablename";$rs = mysql_query($q) or die('problem with query: ' . $q . '<br />' . mysql_error());while ($rw = mysql_fetch_assoc($rs)) foreach ($rw as $key => $value) if ($value == 'abcdef') echo 'The field ' . $key . " holds the value<br />\n";?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/4453-field-name-into-a-variable/#findComment-15459 Share on other sites More sharing options...
alarik149 Posted March 8, 2006 Author Share Posted March 8, 2006 it works...yey..thanks a lot man:) Quote Link to comment https://forums.phpfreaks.com/topic/4453-field-name-into-a-variable/#findComment-15463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.