mac_shinobi Posted January 14, 2010 Posted January 14, 2010 (edited) Got the code below mysql_connect("localhost","backdoor","(*****)"); $tables = mysql_list_tables("dbase"); $count = 0; while ($count < mysql_numrows($tables)) { $category = array(mysql_tablename($tables,$count).","); $category = str_replace(",", "", $category); foreach ($category as $key => $value) { echo ''; echo ''.$value.''; echo ''; } $count++; } //'mysql_tablename($tables,$count).''; //echo mysql_tablename($tables,$count)." "; ?> It seems to put 3 seperate drop down menus and I can't figure out the exact coding for the drop down menu as I want all items in one drop down menu but for some reason its ignoring the tag Edited January 14, 2010 by mac_shinobi
dayzd Posted January 14, 2010 Posted January 14, 2010 You want your select tags to be outside your loop so they're not repeated: echo ''; foreach ($category as $key => $value) { echo ''.$value.''; } echo ''; Change your tag to a tag and you should be golden.
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 (edited) You want your select tags to be outside your loop so they're not repeated: echo ''; foreach ($category as $key => $value) { echo ''.$value.''; } echo '';Change your tag to a tag and you should be golden. tried that and still doing the same - copied and pasted the code that you posted Edited January 14, 2010 by mac_shinobi
dayzd Posted January 14, 2010 Posted January 14, 2010 (edited) Ahh... Is it because your foreach loop is happening inside your while loop? Methinks it probably is! Does this serve you any better? mysql_connect("localhost","backdoor","(*****)"); $tables = mysql_list_tables("dbase"); $count = 0; while ($count < mysql_numrows($tables)) { $category = array(mysql_tablename($tables,$count).","); $category = str_replace(",", "", $category); $count++; } echo ''; foreach ($category as $key => $value) { echo ''.$value.''; } echo ''; //'mysql_tablename($tables,$count).''; //echo mysql_tablename($tables,$count)." "; ?> Edited January 14, 2010 by dayzd Small syntax error 1
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 Ahh... Is it because your foreach loop is happening inside your while loop? Methinks it probably is! Does this serve you any better? mysql_connect("localhost","backdoor","(*****)"); $tables = mysql_list_tables("dbase"); $count = 0; while ($count < mysql_numrows($tables)) { $category = array(mysql_tablename($tables,$count).","); $category = str_replace(",", "", $category); $count++; } echo ''; foreach ($category as $key => $value) { echo ''.$value.''; } echo ''; //'mysql_tablename($tables,$count).''; //echo mysql_tablename($tables,$count)." "; ?> That fixed the first issue but now it is only showing the first table in the drop down menu so I only get one item in the drop down as apposed to all 3 table names
dayzd Posted January 14, 2010 Posted January 14, 2010 mysql_connect("localhost","backdoor","(*****)"); $tables = mysql_list_tables("dbase"); $count = 0; $category = Array(); while ($count < mysql_numrows($tables)) { $category[] = mysql_tablename($tables,$count); $count++; } echo ''; foreach ($category as $key => $value) { echo ''.$value.''; } echo ''; ?> 1
CESIL Posted January 14, 2010 Posted January 14, 2010 Try this mysql_connect("localhost","backdoor","(*****)") $tables = mysql_query("SHOW TABLES from dbase"); echo ''; while ($row = mysql_fetch_row($tables)) { echo ''.$row[0].''; } echo ''; //'mysql_tablename($tables,$count).''; //echo mysql_tablename($tables,$count)." "; ?> 1
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 Try this mysql_connect("localhost","backdoor","(*****)") $tables = mysql_query("SHOW TABLES from dbase"); echo ''; while ($row = mysql_fetch_row($tables)) { echo ''.$row[0].''; } echo ''; //'mysql_tablename($tables,$count).''; //echo mysql_tablename($tables,$count)." "; ?> I get Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\xampp\htdocs\xampp\dbasetables.php on line 3
webman Posted January 14, 2010 Posted January 14, 2010 Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\xampp\htdocs\xampp\dbasetables.php on line 3 Add a ; (semicolon) at the end of the first line (mysql_connect()).
localzuk Posted January 14, 2010 Posted January 14, 2010 Just as a minor thing the 'select name=category' should be 'select name="category"' and the 'option value='blah'> should be 'option value="'blah'">' - This is a HTML thing (ie. all attributes should be contained in " or ').
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 mysql_connect("localhost","backdoor","(*****)"); $tables = mysql_list_tables("dbase"); $count = 0; $category = Array(); while ($count < mysql_numrows($tables)) { $category[] = mysql_tablename($tables,$count); $count++; } echo ''; foreach ($category as $key => $value) { echo ''.$value.''; } echo ''; ?> That did the trick - thanks any chance at some point you can explain the code ?
dayzd Posted January 14, 2010 Posted January 14, 2010 while ($count < mysql_numrows($tables)) { // Loop through all rows in $tables result $category[] = mysql_tablename($tables,$count); // Add table name from selected row to $category array $count++; // Increment counter } echo ''; // Start select dropdown foreach ($category as $key => $value) { // Loop through all $category values echo ''.$value.''; // Add option to select dropdown } echo ''; // Close select dropdown For the record, CESIL's way is more concise and efficient. I just didn't think of it.
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 while ($count < mysql_numrows($tables)) { // Loop through all rows in $tables result $category[] = mysql_tablename($tables,$count); // Add table name from selected row to $category array $count++; // Increment counter } echo ''; // Start select dropdown foreach ($category as $key => $value) { // Loop through all $category values echo ''.$value.''; // Add option to select dropdown } echo ''; // Close select dropdownFor the record, CESIL's way is more concise and efficient. I just didn't think of it. How do you get cecils to work then ?
dayzd Posted January 14, 2010 Posted January 14, 2010 Oh, I haven't tested it...! I'm just assuming it does!
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 Oh, I haven't tested it...! I'm just assuming it does! where does PHP lesson 101 begin ? Thinks me needs more practise and lessons Also thanks for the help !!!
dayzd Posted January 14, 2010 Posted January 14, 2010 You're welcome. I learnt something, to: assumptions are bad! lol
dayzd Posted January 14, 2010 Posted January 14, 2010 I've had a quick poke at CESIL's code (couldn't help myself!): mysql_connect("localhost","backdoor","(*****)"); $tables = mysql_query("SHOW TABLES from dbase"); echo ''; while ($row = mysql_fetch_array($tables, MYSQL_NUM)) { echo ''.$row[0].''; } echo ''; ?> It's the while ($row = mysql_fetch_array($tables, MYSQL_NUM)) { line that needed changing. Now you have two options!
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 I've had a quick poke at CESIL's code (couldn't help myself!): It's the while ($row = mysql_fetch_array($tables, MYSQL_NUM)) { line that needed changing. Now you have two options! changing to what ? changing MYSQL_NUM to a value ie 1, 2 or w/e or what exactly ?
dayzd Posted January 14, 2010 Posted January 14, 2010 It was previously "while ($row = mysql_fetch_row($tables)) {". Change it to "while ($row = mysql_fetch_array($tables, MYSQL_NUM)) {" and it'll work. Or at least it does for me...! NB: MYSQL_NUM is an option of the 'mysql_fetch_array' command, not something you need to change. The other options are MYSQL_ASSOC and MYSQL_BOTH PHP: mysql_fetch_array - Manual 1
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 You're welcome. I learnt something, to: assumptions are bad! lol lol - makes 2 of us
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 It was previously "while ($row = mysql_fetch_row($tables)) {". Change it to "while ($row = mysql_fetch_array($tables, MYSQL_NUM)) {" and it'll work. Or at least it does for me...! NB: MYSQL_NUM is an option of the 'mysql_fetch_array' command, not something you need to change. The other options are MYSQL_ASSOC and MYSQL_BOTH PHP: mysql_fetch_array - Manual Are there any other good php / sql how to's as ideally am trying to put something together here whereby my db has a list of tables which include something along the lines of 1. Models of Devices ie photocopiers, printers etc 2. Relevant List of error codes and what they mean and what to do to resolve each error code with the ability to add extra info to the how to resolve field 3. Relevant List of service modes and what they do With regards to item 2 above for arguements sake lets say I had error code 235 and currently error code for 235 said to get a new network cable and I wanted to add more possible things to try then I could ammend it and say add check network patch panel is patched in and that you can ping the device via its ip address and some other things to do. Also in order to get into this system I need an extra table to store login details for each user who is allowed to get into this system so as to make changes and view all of this info. Clearly I have a long way to go but am just trying to piece the system together first and then worry about how to do a valid_users table and then do the authentication before they are allowed to access the online system Hope that makes sense Also with the database side I need to ensure that the database is setup correctly so im not replicating data etc ( there is a word for it but cant remember it off the top of my head, doh ! )
dayzd Posted January 14, 2010 Posted January 14, 2010 Normalisation That sounds like a fairly involved system to build from scratch. Have you looked into pre-existing solutions - there's bound to be some available. Not too sure about online references (I pick snippets up from all over the place, as I end up doing a lot of Googling when I build things), but if you're up for some hard-copy, I learnt a lot from the second edition of this book (now on ed3): PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide. You can currently [ame=http://www.amazon.co.uk/PHP-MySQL-Dynamic-Web-Sites/dp/032152599X/]get it from Amazon.co.uk[/ame] for a princely £15. 1
localzuk Posted January 14, 2010 Posted January 14, 2010 How about something simpler mac_shinobi? How about an Expert System. This type of system asks you questions and gives you answers, which lead you to further questions - narrowing down the choices until you have got what you want or not. So, say, on 'Node 1' you'd have the question 'What type of device is it?' with 'Printer, Copier' etc... then each link is to a new node 'Node 2' is Printer, with the question of 'Which model is it?' and a list of models. And so on and so forth? An example of such a system (a simple one I will be honest, as it has no other additions) is robopebble. Robopebble | The Programming Pebble If not, that system you are talking of should be relatively easy. You can do the login system using the PEAR::Auth package (save you reinventing the wheel), and the listing of data is fairly simple too. Will error codes be shared between devices? 1
mac_shinobi Posted January 14, 2010 Author Posted January 14, 2010 (edited) How about something simpler mac_shinobi? How about an Expert System. This type of system asks you questions and gives you answers, which lead you to further questions - narrowing down the choices until you have got what you want or not. So, say, on 'Node 1' you'd have the question 'What type of device is it?' with 'Printer, Copier' etc... then each link is to a new node 'Node 2' is Printer, with the question of 'Which model is it?' and a list of models. And so on and so forth? An example of such a system (a simple one I will be honest, as it has no other additions) is robopebble. Robopebble | The Programming Pebble If not, that system you are talking of should be relatively easy. You can do the login system using the PEAR::Auth package (save you reinventing the wheel), and the listing of data is fairly simple too. Will error codes be shared between devices? error codes vary between devices and can give those a try so thanks for the suggestion but would still be good to do something in php / sql myself so I can customize it a bit more. Also would be nice to learn php / sql at the same time Back to the php side of things is it possible to get a select names value in php so when I am changing between the values in the select name I can change the querry ie I select tblMachines and it querries tbl machines or if i select tbl service codes it querries tblservicecodes etc etc Edited January 14, 2010 by mac_shinobi
dayzd Posted January 14, 2010 Posted January 14, 2010 Do you want this to happen automatically when you change the Select dropdown's value, or when you click a submit button? Using a submit button in a form is easier as you should get all variables inside the $_GET or $_POST global (i.e. $_GET['category']) when you submit the form to PHP to handle. If you want it to happen automatically as you change the value, you're gonna have to attach a Javascript function to the onChange() event handler that reads the value and posts it off to the server (php), then handles whatever comes next - navigating to a new page, or inserting new content into the existing one. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now