coogie Posted March 1, 2008 Share Posted March 1, 2008 Hello, i'm new to php and i'm trying to write a script which reads my mysql table. I'd like to achieve all of my rows having a check box and then when i click on the 'edit' button, it makes the specified rows editable and one of the fields (the 'status') becomes a dropdown combobox with the values of (Complete, Pending and active) here is my code so far. Any snippets or links would be really really helpful! thanks a lot in advance <label> <input type="submit" name="edit" id="edit" value="Edit" /> </label> <label> </label> <?php @require_once ('database.php'); //include('loginside.php'); echo "<table border='1'>"; $sql = "SELECT * FROM voucher"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo"<tr>"; foreach($row as $value) { echo "<td>"; echo $value; echo "<td>"; } echo"</tr>"; }; echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 1, 2008 Share Posted March 1, 2008 If you want to build your own editor, that's fine. If you're happy with saving time, then phpMyEdit from http://sourceforge.net/projects/phpmyedit will generate code for you in a few seconds. Quote Link to comment Share on other sites More sharing options...
coogie Posted March 1, 2008 Author Share Posted March 1, 2008 okay, thanks. I'm trying to build my custom 'admin' section for my ecommerce site. Which will have lots of information to manage. do you have other generators i can take a look at? I'm on mac os x leopard Quote Link to comment Share on other sites More sharing options...
coogie Posted March 1, 2008 Author Share Posted March 1, 2008 I've installed phpMyEdit and created access to one table. But how do i go about when you 'edit a table', it makes one of the fields a combo box with 3 options and if it already has a value in the db, that is the currently selected one? Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 1, 2008 Share Posted March 1, 2008 I'm not 100% sure what you're asking, but when I have a database field that has multiple permissible values, I always declare the database field type as ENUM, e.g. ENUM ('Small', 'Medium', 'Large', 'XXX'). phpMyEdit will then auto-generate a dropdown in the edit table for you showing the correct value as selected. Does that help? Quote Link to comment Share on other sites More sharing options...
coogie Posted March 1, 2008 Author Share Posted March 1, 2008 Hi there, thanks a lot for the reply. It works for the 'status' combobox when i configure the database like you said. I'll try to explain the other question more clearly I have two tables. And there is a relationship between the field 'service'. One table is like this (table1) OrderID, email, name, service, status and the other (table2) ServiceID, service, consultant, price, availability I'd like to make it so when editing table1 in my phpmyedit code, the 'service' field is a combobox filled with the values from the table2 ''service' field. regards, James Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 Took me a while to find out how I'd done that in the past. Here's how I did it. Read from one table to get the values I need for the dropdown. Implode them with a comma separator - I usually call that imploded string $pieces, and then in the editor for the other table, I define the field I want to edit using those values as: $opts['fdd']['status1'] = array( 'name' => 'Status 1', 'select' => 'T', 'maxlen' => 32, 'required' => true, 'sort' => true, 'values' => $pieces ); if you compare that with how the enum fields work in the generated editor script, it should become clear (I hope) Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 Thanks a lot for the help!! Where do i look to input the connection the other table name? at the moment it only connects to the one table Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 Forgot that bit What I did was change the first few lines of the generated file so that it connected to the database, set the table name to the 'other' table, ran a query to read what it needed from the other table in order to generate the $pieces array, and THEN changed the tablename to the name of the table I really wanted to edit. This was a self-invented work-around rather than something that's built in to the original script, but it seems to work well for me. Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 Sounds logical Could i see your code snippet of how you did that? Also, i have another question with phpmyedit. how possible/complicated would it be for me to add a button called 'generate order'. Which then basically opens a new page (or saves a file?) with all of the info from 3 different tables, nicely laid out. So that i can then print it. So it would display everything with the orderID from 3 tables. WOuld this be possible to integrate do you think? Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 I normally keep my db-conn information in a separate file and slightly modify the phpMyEdit output to re-define the $opts array values. If you review the code below in concert with my original suggestion of where to use $pieces that should get you pretty close to where you want to be: include("../includes/db_conn.php"); // use a externally defined db_conn file // MySQL host name, user name, password, database, and table $opts['hn'] = $db_host; $opts['un'] = $db_login; $opts['pw'] = $db_pass; $opts['db'] = $db_name; $opts['tb'] = 'classified'; $other_table = "wombats"; // the 'other' table $pieces = ""; // let's get the array of alternatives from ANOTHER table mysql_connect($db_host, $db_user, $db_pass) or die ("Can't connect!"); mysql_select_db($db_name) or die ("Can't open database!"); $query = "SELECT DISTINCT some_fieldname from $other_table"; // only get unique values for some_fieldname $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $pieces.= $row['some_fieldname']. ","; // construct the string we'll use later } Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 Thanks so much for the help Andy, I really appreciate it I'm going to try this for a while and will report back should i get stuck -coogie Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 It took me a while to track down where I'd used the technique. I'm hoping there's enough info in the two relevant posts that - with a little work - you'll be able to get your stuff to do what you need. phpMyEdit has saved me weeks (and it's client-proof as well!) Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 I will give it my very best shot! Do you think it's going to be possible for me to create a magic button that creates a table in a new page with all of the info of an order on it? that would be an amazing feature for me i'm tired of pasting everything and making mistakes! Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 Do you think it's going to be possible for me to create a magic button that creates a table in a new page with all of the info of an order on it? that would be an amazing feature for me i'm tired of pasting everything and making mistakes! I used to think like that. If only I had a magic button I'm afraid the closest you'll get to a magic button is a link that passes a specific record number to a db script to abstract and display the information relating to that record number. Once it's done right once, it'll work for every order. Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 So i would create a separate php/html script which loads the data exactly how i want it to look, with a query where order = $frommyphpedit this would make sense. Perhaps clicking on the order ID of the entry would even mean not having to have a magic button Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 Bingo! Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 Ok great, sounds easier than having to make a button and do it all in the phpmyedit. Is it possible to insert PHP information into my HTML table. so for example, i have this table: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="341" border="1"> <tr> <td width="93"> </td> <td width="232"> </td> </tr> <tr> <td>Order ID</td> <td> </td> </tr> <tr> <td>Email</td> <td> </td> </tr> <tr> <td>Price</td> <td> </td> </tr> <tr> <td>Status</td> <td> </td> </tr> </table> </body> </html> and i connect to my database like this: <?php @require_once ('database.php'); echo "<table border='1'>"; $sql = "SELECT * FROM orders"; /////where orderid = FROMmyPHPEDIT $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { }; ?> How can i put those 4 fields (order id, email, price, status) into my table viewed in an html page, which i can then print? sorry, i am abusing your helpfulness now! Quote Link to comment Share on other sites More sharing options...
coogie Posted March 2, 2008 Author Share Posted March 2, 2008 ok forget that last question, you can drag and drop from dreamweaver! Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 That's the spirit!! Quote Link to comment Share on other sites More sharing options...
coogie Posted March 6, 2008 Author Share Posted March 6, 2008 I created a new thread about communicating from phpmyedit to another php file! http://www.phpfreaks.com/forums/index.php/topic,186046.msg833144.html#msg833144 Still learning all of this I do like that drag and drop from dreamweaver DB connections... genius Quote Link to comment 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.