Jump to content

Adding 'edit' checkboxes to each of my rows


coogie

Recommended Posts

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>";
?>

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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!)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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.