473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Incrementing a variable in a loop.

16 New Member
Expand|Select|Wrap|Line Numbers
  1. create procedure view_select
  2. (coll int(11))
  3. begin
  4. declare x  int;
  5. declare y int;
  6. set x=0;
  7. select count(*) into y from s_details where college_code=coll;
  8. while(x<y) do
  9. select day_number,title,first_name,middle_name,last_name,
  10. date_of_birth,e_mail,ref_number,
  11. date_of_entry_of_details,course_id,x+1 from s_details;
  12. set x=x+1;
  13. end while;
  14. end//
  15.  

How to increment the value of x alone for each record being displayed?
In this the select statement is repeated as many times as x?
How to solve this problem?
Sep 28 '07 #1
9 4613
pbmods
5,821 Recognized Expert Expert
Heya, Praveena.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Change:
Expand|Select|Wrap|Line Numbers
  1. date_of_entry_of_details,course_id,x+1 FROM s_details;
To:
Expand|Select|Wrap|Line Numbers
  1. date_of_entry_of_details,course_id, x := x + 1 FROM s_details;
Sep 28 '07 #2
praveena mani
16 New Member
Heya, Praveena.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Change:
Expand|Select|Wrap|Line Numbers
  1. date_of_entry_of_details,course_id,x+1 FROM s_details;
To:
Expand|Select|Wrap|Line Numbers
  1. date_of_entry_of_details,course_id, x := x + 1 FROM s_details;
it becomes infinite loop.
I want x to act like serial number for my table.
Everytime wen a record is displayed x shud be incremented by 1.
Can u pls help me to implement this?
Sep 28 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, Praveena.

Are you trying to set a variable LIMIT for your SELECT query?

Try using a Prepared Statement.
Sep 28 '07 #4
praveena mani
16 New Member
Heya, Praveena.

Are you trying to set a variable LIMIT for your SELECT query?

Try using a Prepared Statement.

I jus want to view the records what i ve entered in my table.
But with one more field added while displaying that is the serial number x.
I am getting the count of total number of records in the table into variable y.
So until x<y the loop should execute but it is not happening why?
Sep 28 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya, Praveena.

This line:
Expand|Select|Wrap|Line Numbers
  1. SELECT day_number,title,first_name,middle_name,last_name, 
  2. date_of_birth,e_mail,ref_number,
  3. date_of_entry_of_details,course_id,x := x + 1 FROM s_details;
  4.  
does select every record from the table. You don't need to use a loop here.
Sep 28 '07 #6
praveena mani
16 New Member
Heya, Praveena.

This line:
Expand|Select|Wrap|Line Numbers
  1. SELECT day_number,title,first_name,middle_name,last_name, 
  2. date_of_birth,e_mail,ref_number,
  3. date_of_entry_of_details,course_id,x := x + 1 FROM s_details;
  4.  
does select every record from the table. You don't need to use a loop here.
i even tried without a loop but that x=x+1 doesnt get incremented.
each time it is displaying zero only for x. Why?
Sep 28 '07 #7
pbmods
5,821 Recognized Expert Expert
Heya, Praveena.

The colon is important.
Sep 28 '07 #8
praveena mani
16 New Member
Heya, Praveena.

The colon is important.
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE view_select
  2. (coll INT(11))
  3. BEGIN
  4. DECLARE x INT;
  5. set x=0
  6. SELECT course_id,x:=x+1 FROM s_details;
  7. end//
  8.  
this is what u asked me to do right?
but this gives an error.
if i remove the colon it is working
Sep 28 '07 #9
praveena mani
16 New Member
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE view_select
  2. (coll INT(11))
  3. BEGIN
  4. DECLARE x INT;
  5. set x=0
  6. SELECT course_id,x:=x+1 FROM s_details;
  7. end//
  8.  
this is what u asked me to do right?
but this gives an error.
if i remove the colon it is working
it is working in the sense the query is ok..
but x is always displayed as 0.
Sep 28 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6869
by: J. Campbell | last post by:
Hi everyone. I'm sure that this is common knowledge for many/most here. However, it was rather illuminating for me (someone learning c++) and I thought it might be helpful for someone else. I'm sure I'll get scolded for an OT post, but I think issues of this type should be of interest to programmers until they get a handle on them. I was reading some old threads about the relative advantages of using ++i vs i++ (I won't rehash the many...
2
26316
by: Ken | last post by:
The fact that you can not reassign a variable in XSL is an endless source of frustration, causing you to jump through all sorts of non-intuitive hoops. In this case, however, the lack of reassignment has me totally perplexed on how to achieve a solution to the following problem: (These are illustrative fragments) XML:
2
4872
by: John Wilkinson | last post by:
Hi, I am new to XSLT. My problem is that I wish to create an HTML table, and give each row an incrementing number from 1.This would increment every itteration of a for-each loop. The XSLT fragment I have tried is: <xsl:variable name="test" select="0"></xsl:variable> <table border="1"> <tbody> <tr bgcolor="#9acd32">
2
3003
by: dan | last post by:
I have 2 tables, tab1 ( integer incremented sequence , col2, col3 ) and tab2 ( integer from tab1, col4, col5 ). When I call this function to add a record to each table: LOOP select nextval('sequence') into id_car; // for looping INSERT INTO tab1 VALUES (default, col2, col3);
27
8949
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in advance. Erik
3
7241
by: boaring | last post by:
I need to use Macro's in Excel and always the same changes to 31 Sheets. (31 days in the Month). I'm trying to use a FOR loop but cannot get the correct format to have the sheet number to increment by 1 in each loop. Below is a silly little Macro but indicates what my problem is. I have tried inserting my variable intSheet in various ways including concatenation to no avail. Any help would be greatly appreciated. Thankyou Sub Macro2() '...
4
1824
by: masterpaladin38 | last post by:
I've been working on this problem for some time and I must say I'm stump. Any help would be appreciated. Basically what I'm trying to do is write the results of a loop to a new text file with every pass. For example the user chooses that the loop should run 10 times. I want to write the results of each pass of the loop to a text file by incrementing the filename and creating a new text file. So if it the loop went through 10 passes I...
2
1534
by: Arekkusu | last post by:
Hi, nice to meet everyone, im Arekkusu and im new to the forums. I have a slight problem..hopeing you guys and gals can help with. Its about trying to get a variable ($i), to increase by one every time a number of strings from the $POST array is written to a flat file. Does that make sense? This what I got so far. $racerDetails = $_POST; //write to file//
3
3338
by: Elementary | last post by:
I have a number of variables, e.g. X1, X2, X3, X4, X5. I want to select only the ones that are non zero(there will only be 2 or 3 at any time), and record them as Y1, Y2 and Y3 I want to know the best way of incrementing the name of the variable, e.g. the variable in a loop is X + (num) I was trying Num1=1 Num2=1
9
3363
by: subramanian100in | last post by:
The following portion is from c-faq.com - comp.lang.c FAQ list · Question 6.13 int a1 = {0, 1, 2}; int a2 = {{3, 4, 5}, {6, 7, 8}}; int *ip; /* pointer to int */ int (*ap); /* pointer to array of int */\ ap = &a1; printf("%d\n", **ap);
0
8310
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,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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,...
1
6167
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
5632
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
4158
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...
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1620
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.