Solved

PHP Help Needed

Posted on 2013-01-11
5
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Cornelia Yoder
Cornelia Yoder 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Suggested Solutions

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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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