Solved

PHP Help Needed

Posted on 2013-01-11
5
416 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now