473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to call a column value from a tablein database

9 New Member
Expand|Select|Wrap|Line Numbers
  1. $sql = "UPDATE `students` 
  2.    SET `name` = '$name',
  3.    `surname` = '$surname',
  4.    `father` = '$father',
  5.    `mobile` = '$mobile',
  6.    `address` = '$address' 
  7.    WHERE 
  8.       `students`.`rollnum` = '$501' LIMIT 1";
  9.  
  10. mysql_query($sql) or die ("Error: ".mysql_error());
  11.  
  12. WHERE `students`.`rollnum` = '501'
how can i update a rollnumber without giving its value directly... if i want to update details of 502,it ll be waste of time to open this file and change number each time...
please help
Aug 18 '12 #1
4 1994
Luuk
1,047 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1.   $rollnum="501";
  2.   $sql= "....WHERE `students`.`rollnum` = '$rollnum' LIMIT 1";
  3.  
Aug 18 '12 #2
mskctg
9 New Member
use a variable for rollNum
your code should be look like this
Expand|Select|Wrap|Line Numbers
  1. $sql = "UPDATE students SET name = $name, surname = $surname, father = $father, mobile = $mobile, address = $address, Where rollnum = $rollnum";
  2. mysql_query($sql) or die ("Error: ".mysql_error());
Aug 18 '12 #3
Luuk
1,047 Recognized Expert Top Contributor
@mskctg: but wat if $name contains one (or more) spaces?
The original code was better, it included the name in single quotes..

About 'LIMIT 1': we dont have enough info to tell if this is correct, or not....
Aug 18 '12 #4
mskctg
9 New Member
@Luuk: Why should we use spaces in variable name? If its needed we should use underscore like $first_name.

'LIMIT' keyword is used to limit the query result. if we use 'LIMIT 1' it will show only one row from our query result. if we use 'LIMIT 5' it will show first five rows.

'LIMIT' keyword take TWO Parameter. Suppose We use 'LIMIT 5,10' it will show 10 rows starting from row number 5.
Sep 10 '12 #5

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

Similar topics

0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
3
by: Prabhudhas Peter | last post by:
I want to assign null value to a column in the database which is decalred as an integer from VB.net... Is there any specific keyword like vbNull as in vb 6.0. -- Peter...
2
by: Microsoft News Group | last post by:
I am trying to get a value from the MIN column in my database. I can not seem to get the IF statement to be true, even thou my debugging says the column value is 0, but it is not hitting the...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
0
by: Joe Meng | last post by:
Greetings, I've seen this question asked and answered here, just not completely yet. I'm wondering how to use a column value as a table name in another query. So far it's looking like you must...
10
by: TF | last post by:
Very newbie question and I hope this is the right group. I have a table on a web page which contains info about paint colors. One column contains the hex value for the color's RGB value. I want...
1
by: Dolly Kumari | last post by:
Hi, I want to write a Program in vb which will accept any Access database (.mdb file) and search a particular column value in all tables present in the database and will give the result as table...
0
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all...
4
by: coder86 | last post by:
Hi, I am new to this site . I am looking for some help in updating my database from the value selected by user. Heres my page I have a table with rows of ID and its status. Status is a drop...
3
by: sri devi | last post by:
Hi Frnz, Kindly, help me. How to compare a single row with a whole column value in C3 For Ex: ROW COLUMN ---------------------- SRI DEVI BABU ...
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
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
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...

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.