Thomisback Posted April 16, 2008 Share Posted April 16, 2008 Hello, I was just wondering, is it possible to retrieve e.g. database names/tables/columns from MySQL and retrieve them as radio buttons (an array) for my administration panel & edit them? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/ Share on other sites More sharing options...
schme16 Posted April 16, 2008 Share Posted April 16, 2008 I don't see why not. I'm not sure of the specific code for the job, but it'd be a mysql_query("") with a while and a mysql_fetch_array. something like this: $read_tables = mysql_query(" sql query goes here (cheack the MySQL Manual for this)"); //this will read each table and output its values to a variable called table while($table = mysql_fetch_array($read_tables)) { print' <label> $table['name'] <input type="radio" id="'.$table['name'].'" name"'.$table['name'].'" /> </label> <br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518246 Share on other sites More sharing options...
Thomisback Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks! Unfortunately I can't find the code to retrieve database & table names, I did find the code to retrieve column names. Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518258 Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 $con=mysql_connect("localhost","username","password"); mysql_connect_db("databasename,$con); $read_tables = mysql_query(" select fieldname from tablename"); Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518264 Share on other sites More sharing options...
schme16 Posted April 16, 2008 Share Posted April 16, 2008 http://au2.php.net/manual/en/function.mysql-tablename.php This will allow you to dynamically list all tables in a database. Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518266 Share on other sites More sharing options...
Thomisback Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks all, I also found how to retrieve the database names: http://au2.php.net/manual/en/function.mysql-db-name.php Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518274 Share on other sites More sharing options...
Thomisback Posted April 16, 2008 Author Share Posted April 16, 2008 I successfully did it but I now have too many tables (lol) so I changed my mind to a combo box but I can't figure out how to do it. For my radio input I now have: echo "<label>"; print "$row[0]\n"; echo "<input type=radio id="; print "$row[0]\n"; echo "name="; print "$row[0]\n"; echo "/> </label> <br>"; So how would I configure a combo box like this to do the same? <input type="select" name="OS"> <option value="Win95">Windows 95/98</option> <option value="WinNT">Windows NT/2000</option> <option value="OSX">Macintosh OS X</option> <option value="OS9">Macintosh OS 9</option> <option value="Linux">Linux</option> <option value="Solaris">Solaris</option> <option value="BSD">FreeBSD</option> </input> Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518308 Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 <select name=""> <option value="">value</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518313 Share on other sites More sharing options...
Thomisback Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks but now I get a different combo box for each table :/ Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518316 Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 <?php mysql_connect("localhost", "root", ""); $result = mysql_list_tables("test"); $num_rows = mysql_num_rows($result); echo "<select name=''>"; for ($i = 0; $i < $num_rows; $i++) { echo "<option value=''>".mysql_tablename($result, $i)."</option>"; } echo "</select>"; mysql_free_result($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518317 Share on other sites More sharing options...
Thomisback Posted April 16, 2008 Author Share Posted April 16, 2008 !wow thanks a lot, that seriously helped Quote Link to comment https://forums.phpfreaks.com/topic/101319-solved-radio-button-array/#findComment-518318 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.