473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SQL syntax to update records with diff'rent function generated random PINS

I use a function, myrandomPIN (), to generate random PIN numbers.

The following sql query updates records with the SAME PIN number but.
I want to generate DIFFERENT pin numbers for every record. The
function is ok but I can't figure out how to run it individually for
each record. In other words I do not know the correct syntax to use
UPDATE in a loop (if necessary) so that a different call to the
function is done every time or ecah record ends up with a different
PIN.

Or may be this can be done with a single mysql_query($sql2)???

----------------------------------------------------------------------------
$qr = @mysql_query($sqlb1) or die("ERROR");
$rs1 = mysql_fetch_array($qr);
$thepin=myrandomPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecode."'";
$qr = @mysql_query($sql2) or die("ERROR"");
--------------------------------------------------------------------------

Thanks
Jul 17 '05 #1
3 2465

"John Pastrovick" <pa*********@hotmail.com> wrote in message
news:a2**************************@posting.google.c om...
I use a function, myrandomPIN (), to generate random PIN numbers.

The following sql query updates records with the SAME PIN number but.
I want to generate DIFFERENT pin numbers for every record. The
function is ok but I can't figure out how to run it individually for
each record. In other words I do not know the correct syntax to use
UPDATE in a loop (if necessary) so that a different call to the
function is done every time or ecah record ends up with a different
PIN.

Or may be this can be done with a single mysql_query($sql2)???

-------------------------------------------------------------------------- -- $qr = @mysql_query($sqlb1) or die("ERROR");
$rs1 = mysql_fetch_array($qr);
$thepin=myrandomPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecode."'";
$qr = @mysql_query($sql2) or die("ERROR"");
--------------------------------------------------------------------------

Thanks


The important thing about your UPDATE statement is the WHERE clause - since
you only retrieve one record (I hope!), you can only update one at a time
this way.

For multiple updates of rows like this pseduocode:
update set (a=1 where id=1, a=2 where id=2)
you'd need to create and execute a temporary stored procedure (MySQL 5 and
up - http://dev.mysql.com/doc/mysql/en/St...ocedures.html). If you know
them, it's easy enough, but if you don't, stick to your original loop, it's
no hardship.

Garp
Jul 17 '05 #2
"Garp" <ga***@no7.blueyonder.co.uk> wrote in message news:<U9*********************@news-text.cableinet.net>...
"John Pastrovick" <pa*********@hotmail.com> wrote in message
news:a2**************************@posting.google.c om...
I use a function, myrandomPIN (), to generate random PIN numbers.

The following sql query updates records with the SAME PIN number but.
I want to generate DIFFERENT pin numbers for every record. The
function is ok but I can't figure out how to run it individually for
each record. In other words I do not know the correct syntax to use
UPDATE in a loop (if necessary) so that a different call to the
function is done every time or ecah record ends up with a different
PIN.

Or may be this can be done with a single mysql_query($sql2)???

--------------------------------------------------------------------------

--
$qr = @mysql_query($sqlb1) or die("ERROR");
$rs1 = mysql_fetch_array($qr);
$thepin=myrandomPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecode."'";
$qr = @mysql_query($sql2) or die("ERROR"");
--------------------------------------------------------------------------

Thanks


The important thing about your UPDATE statement is the WHERE clause - since
you only retrieve one record (I hope!), you can only update one at a time
this way.

For multiple updates of rows like this pseduocode:
update set (a=1 where id=1, a=2 where id=2)
you'd need to create and execute a temporary stored procedure (MySQL 5 and
up - http://dev.mysql.com/doc/mysql/en/St...ocedures.html). If you know
them, it's easy enough, but if you don't, stick to your original loop, it's
no hardship.

Garp

In ASP I looped through the set assigning new values and then OUTSIDE
the loop I updated the set rs1.UPDATE. I do not know how to do this
in PHP.
Do I have to send a query for every record in a loop or is there a way
to set the records value individually in a loop and then send a query
ONCE outside the loop to update the whole table?? Can anybody explain?

I feel that sending a query foer every record is not the efficient
way to do it and there can be a similar way to ASP.

Thanks
Jul 17 '05 #3
"Garp" <ga***@no7.blueyonder.co.uk> wrote in message news:<U9*********************@news-text.cableinet.net>...
"John Pastrovick" <pa*********@hotmail.com> wrote in message
news:a2**************************@posting.google.c om...
I use a function, myrandomPIN (), to generate random PIN numbers.

The following sql query updates records with the SAME PIN number but.
I want to generate DIFFERENT pin numbers for every record. The
function is ok but I can't figure out how to run it individually for
each record. In other words I do not know the correct syntax to use
UPDATE in a loop (if necessary) so that a different call to the
function is done every time or ecah record ends up with a different
PIN.

Or may be this can be done with a single mysql_query($sql2)???

--------------------------------------------------------------------------

--
$qr = @mysql_query($sqlb1) or die("ERROR");
$rs1 = mysql_fetch_array($qr);
$thepin=myrandomPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecode."'";
$qr = @mysql_query($sql2) or die("ERROR"");
--------------------------------------------------------------------------

Thanks


The important thing about your UPDATE statement is the WHERE clause - since
you only retrieve one record (I hope!), you can only update one at a time
this way.

For multiple updates of rows like this pseduocode:
update set (a=1 where id=1, a=2 where id=2)
you'd need to create and execute a temporary stored procedure (MySQL 5 and
up - http://dev.mysql.com/doc/mysql/en/St...ocedures.html). If you know
them, it's easy enough, but if you don't, stick to your original loop, it's
no hardship.

Garp

In ASP I looped through the set assigning new values and then OUTSIDE
the loop I updated the set rs1.UPDATE. I do not know how to do this
in PHP.
Do I have to send a query for every record in a loop or is there a way
to set the records value individually in a loop and then send a query
ONCE outside the loop to update the whole table?? Can anybody explain?

I feel that sending a query foer every record is not the efficient
way to do it and there can be a similar way to ASP.

Thanks
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ben | last post by:
This is probably a common problem with a standard design pattern, but I'm having trouble finding the solution. I have a table with a lot of columns, for this example I'll just use three but in...
0
by: chan | last post by:
how to apply online update function into program (the effect just like Norton system work live update) The situation is below: I want to develop a program that contains some product...
3
by: | last post by:
Hi, I have a major problem. I use Windows 2000 highest SP and ACCESS 2000 inside Office 2000 SP-3. I want to use the following simple command inside ACCESS in VBA UPDATE tbl_SATURN_Benutzer...
3
by: Luboą ©lapák | last post by:
Hi, I save multiline value in Column "Address" in Table in DataSet , but after UPDATE (save new row on SQL Server) is saved only first line from all lines in "Address" column. I have also second...
1
by: Dave | last post by:
Ok then... simple little exercise for me to learn ASP.NET and the simplest things are hanging me up. Like this: I have an .mdb that I am using the Matrix generated Select code to read from. The...
4
by: Child | last post by:
I am feeling frustrated and I am willing to bet its something stupid but I could really use some help. I have a class called anEvent. On my web form I have a button which creates a new anEvent...
1
by: Chris | last post by:
I have a snippet of a function below I fire up in the body tag of my webpage to show a hidden layer and do some stuff when any link with the name "showlink" is clicked. In the displayed layer...
1
by: adamjblakey | last post by:
Hi, I have a function which updates a cart but it is not working correctly. Basically if i have e.g. 2 x Red Shoes 3 x Blue Shorts And then i change the qty of the blue shorts to 4 and...
3
by: pinko1204 | last post by:
My Update function cannot successful update to sql table even don't have any error. Please help to check .....thx PHP1 <?php require_once 'header.php'; ?> <style type="text/css"> <!--
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.