473,768 Members | 7,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($sq l2)???

----------------------------------------------------------------------------
$qr = @mysql_query($s qlb1) or die("ERROR");
$rs1 = mysql_fetch_arr ay($qr);
$thepin=myrando mPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecod e."'";
$qr = @mysql_query($s ql2) or die("ERROR"");
--------------------------------------------------------------------------

Thanks
Jul 17 '05 #1
3 2487

"John Pastrovick" <pa*********@ho tmail.com> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
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($sq l2)???

-------------------------------------------------------------------------- -- $qr = @mysql_query($s qlb1) or die("ERROR");
$rs1 = mysql_fetch_arr ay($qr);
$thepin=myrando mPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecod e."'";
$qr = @mysql_query($s ql2) 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.blue yonder.co.uk> wrote in message news:<U9******* **************@ news-text.cableinet. net>...
"John Pastrovick" <pa*********@ho tmail.com> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
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($sq l2)???

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

--
$qr = @mysql_query($s qlb1) or die("ERROR");
$rs1 = mysql_fetch_arr ay($qr);
$thepin=myrando mPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecod e."'";
$qr = @mysql_query($s ql2) 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.blue yonder.co.uk> wrote in message news:<U9******* **************@ news-text.cableinet. net>...
"John Pastrovick" <pa*********@ho tmail.com> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
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($sq l2)???

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

--
$qr = @mysql_query($s qlb1) or die("ERROR");
$rs1 = mysql_fetch_arr ay($qr);
$thepin=myrando mPIN();
$sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecod e."'";
$qr = @mysql_query($s ql2) 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
3698
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 reality its more like 20. Create Table myTable (int col_one primary key, int col_two, varchar(20) col_three) etc... I want to write a sproc that allows updating of this column. Say I
0
1417
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 information (in the database) for customer choosing.
3
4133
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 SET bool_IstDatensatzAktuell = False, bool_ImportCheckFlag = True, dat_Löschdatum = #01/25/2005 18:38:17# WHERE ((bool_ImportCheckFlag = False) AND (dat_Löschdatum = Null) AND
3
1679
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 Column "Notes" where are saving also multiline values, but there is no problem with saving. All is same like Column "Address". Do you have any ideas? Thanks Lubos
1
1434
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 SELECT function it generates works fine. Now I am trying to Update one of the records in the little .mdb... the first record... the following code executes without error, but nothing changes in the .mdb either. What simple little thing am I...
4
1166
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 and loads the form data into the new event. It then sends that event to a class function to try and update the data in the database. When I hit the button, it appears that nothing happens, no error message, just a return to the previous state of...
1
2222
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 there is some html and more javascript. How would I update the value of "str" with "node_id" each time a link is clicked? I can't figure it out... Many thanks,
1
1362
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 pass to the update function it just completely removes the first lot of items in the list e.g. the 2 x red shorts. The data is stored in a session like so:
3
2320
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
9576
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9961
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9843
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5283
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.