Jump to content

Updating one column of DB ... Best way?


lightsguy

Recommended Posts

Spent most of the day trying to figure this out. I need to determine the best way to update a single column in the data base. The page that loads would show all records WHERE complete = No. Then, the user could indicate that the request has been done. (I'm not really partial to a particular method. Seeing as how I can't get any of my ideas to work, I won't argue with anything thrown out there.)

 

Once they say the request is done, the record is submitted. Currently, the page redirects back to itself (test_5.php) simply because I have no where else for it to go.

 

For the record: I know my $query as written will update every record in the DB. I never could figure out how to isolate only the records I chose. Most of what you will find below is a result of searching the archives here and other sources. Obviously, I don't know something critical, which is hampering my progress. If you can point me in the right direction, it would be greatly appreciated.

 

<?php
if(isset($_POST['add']))
{
include 'config.php';
include 'opendb.php';

$query = "UPDATE cable SET complete = 'Yes' WHERE complete = 'No'";
mysql_query($query) or die('Error, query failed');
unset ($_POST['add']);
include 'closedb.php';
include("test_5.php") ;
}
else
{
include 'config.php';
include 'opendb.php';
$query  = "SELECT date,emp_name, emp_email, emp_phone,server,location,switch,port FROM cable
			WHERE complete = 'No'";
$result = mysql_query($query);
echo	"<form method=\"post\"><table width=\"100%\"><tr><td>Date</td><td>Name</td><td>Email</td>" .
"<td>Phone</td><td>Group</td><td>Server</td><td>Location</td><td>Switch</td><td>Port</td>" .
"<td>Complete?</td></tr>" ;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
	echo	"<tr>	<td>{$row['date']}</td>" .
		"<td>{$row['emp_name']}</td>" .
		"<td>{$row['emp_email']}</td>" .
		"<td>{$row['emp_phone']}</td>" .
		"<td>{$row['emp_group']}</td>" .
		"<td>{$row['server']}</td>" .
		"<td>{$row['location']}</td>" .
		"<td>{$row['switch']}</td>" .
		"<td>{$row['port']}</td>" .
		"<td><select name=\"done\"><option>Yes</option><option selected>No</option></td>" ;
	} 
	echo"</tr></table><input name=\"add\" type=\"submit\" id=\"add\" value=\"Submit\"></body></html>";
	include 'closedb.php';
}

?>

Link to comment
https://forums.phpfreaks.com/topic/38357-updating-one-column-of-db-best-way/
Share on other sites

"I never could figure out how to isolate only the records I chose."

WHERE id = '$id'

 

What are you stuck on?

 

I know that I would have to set $id to match the rows that I want to update. Obviously, the only rows I want to update are the ones that are complete, and the user has indicated as so. If they chose "Yes" from the dropdown (as I have it written, which may I not work, I admit) how do I tie that to $id ?

Well, that pretty much confirms I'm in over my head here. That's what I get for taking on projects at work.

 

This is a case where I'm fully aware I don't know enough to properly describe my next problem. Thanks for the help. I've got more research to do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.