Solved

PHP Help Needed

Posted on 2013-01-11
5
438 Views
Last Modified: 2013-01-11
I have a table in my database named clerk_names. In this database there is a colum named active & by default they are all set to 0. Will this code mark all the entries in the active columnn to 1?

<?phprequire('connection.php');$query="UPDATE clerk_names SET active = '1' ";?>

Open in new window


Basically, I will be calling this script from a web page & when it is called I need it to mark all the 0's in active field to 1. There are only 10 entries in the active field. Thanks for any help provided.
0
Comment
Question by:wantabe2
5 Comments
 
LVL 12

Expert Comment

by:adrian_brooks
ID: 38768681
That code will update every record in your table setting active to 1.
0
 
LVL 12

Assisted Solution

by:adrian_brooks
adrian_brooks earned 200 total points
ID: 38768685
If you wish to mark all 0's to 1's, do this instead;

$query="UPDATE clerk_names SET active = '1'  where active = '0'";

Open in new window

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 200 total points
ID: 38768727
The answer from looking at the code is no.
<?php require('connection.php');$query="UPDATE clerk_names SET active = '1' ";?>

Open in new window

should be
<?php 
require('connection.php');
$query="UPDATE clerk_names SET active = '1' where active = '0' ";
$result = mysql_query($query) or die("There was an error");
?>

Open in new window

0
 
LVL 27

Assisted Solution

by:yodercm
yodercm earned 100 total points
ID: 38768745
It matters if the only two possible values in that field are 0 and 1.

What you wrote will set ALL values in that column to 1 regardless of what is there.

If you want to change only the 0's to 1's, then use what adrian_brooks and roads_roads gave you.

If there are other possible values, including blanks for example, you might need more decision making in your query.
0
 
LVL 15

Author Comment

by:wantabe2
ID: 38768759
Thanks everyone!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question