473,395 Members | 1,622 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,395 software developers and data experts.

database variables calculation in ruby

Hi everybody, in my database, am trying to print the value of total and then add it to the price,
i was able to fetch the value of total but when i tried to add it to to price so as to get value of sum in this line
of code

Expand|Select|Wrap|Line Numbers
  1.  
  2.     sum = price + %s, row[0]  
  3.     puts "sum"
  4.  
nothing happens. where am i supposed to perform the operations, is outside the loop. below is the code, any help please

Expand|Select|Wrap|Line Numbers
  1.  
  2.     #!/Ruby19/bin/ruby 
  3.     require 'cgi'
  4.  
  5.     cgi = CGI.new
  6.     puts cgi.header
  7.  
  8.     require "dbi"
  9.  
  10.  
  11.  
  12.      price = '100'
  13.     begin
  14.        # connect to the MySQL server
  15.          conn = DBI.connect("DBI:Mysql:db:localhost", 
  16.                             "root", "root566")
  17.  
  18.         rs = con.query("SELECT total from product where product_id = '20'")
  19.  
  20.        row = stmt.fetch do
  21.  
  22.        end
  23.        puts "<font color=green size=4><b>get total values</b></font><br><br>"
  24.  
  25.      printf '<b>total:</b> %s<br>', row[0]
  26.  
  27.      sum = price + %s, row[0]  
  28.     puts "sum"
  29.  
  30.  
  31.  
  32.     rescue Mysql::Error => e
  33.         puts e.errno
  34.         puts e.error
  35.  
  36.     ensure
  37.         con.close if con
  38.     end
  39.  
  40.  
Nov 23 '11 #1
0 2212

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

Similar topics

5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
16
by: Craig L | last post by:
I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but...
0
by: cdginc | last post by:
Hello, I am trying to implement a sales cart application that uses VBScript and writes the data to an Access database. This is a prepackage software that I am trying to customize for my needs. ...
1
by: Azel | last post by:
Hi, I am trying to learn ADO.net and I keep running into problems trying to insert data into my Access Database: data.mdb. here is my code: <code> // Database Variables
2
by: Sunnyrain | last post by:
When I tried to declare object variables below in Access, the compiler couldn't find its type. It showed me a compile error: user-defined type not defined. Sub aTest() ' Declare variables....
22
by: Francois | last post by:
I discovered Python a few months ago and soon decided to invest time in learning it well. While surfing the net for Python, I also saw the hype over Ruby and tried to find out more about it, before...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
9
by: StarLavender | last post by:
Hi. I have a calculate.js javascript file where all the function that execute the calculation is consist in this file. Now, I want to retrieve a data from the database for calculation and be done in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.