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

Set Variable to One Column

Is it possible to set a variable from a query that will return one
row ie..

$control = mysql_query("SELECT control FROM table WHERE id = '1'");
Jul 21 '05 #1
2 1458
>Is it possible to set a variable from a query that will return one
row ie..

$control = mysql_query("SELECT control FROM table WHERE id = '1'");


Yes, but $control is a MySQL result handle, not the value.
To get the value (and there are a number of different ways to do this,
and you really need to do some error checking in case there was no
row with id = 1):

$r = mysql_fetch_result($control);
$value = $r[0];
/* we now have the value you wanted in $value */
echo "$value";
mysql_free_result($control);

Gordon L. Burditt
Jul 21 '05 #2

I appreciate it. I am new in PHP. I knew about the result handle and
was just trying to show an example. In other languages I am able to
do something similar to that example all in one line and is what I was
aiming for. Two extra lines will do though.

Again thanks for you Help.

On Wed, 20 Jul 2005 21:06:58 -0000, go***********@burditt.org (Gordon
Burditt) wrote:
Is it possible to set a variable from a query that will return one
row ie..

$control = mysql_query("SELECT control FROM table WHERE id = '1'");


Yes, but $control is a MySQL result handle, not the value.
To get the value (and there are a number of different ways to do this,
and you really need to do some error checking in case there was no
row with id = 1):

$r = mysql_fetch_result($control);
$value = $r[0];
/* we now have the value you wanted in $value */
echo "$value";
mysql_free_result($control);

Gordon L. Burditt


Jul 21 '05 #3

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

Similar topics

3
by: Nelson Broat | last post by:
In jsp land you can have the following: <% String name = "Nelson"; %> Hi, my name is <%= name %>. Such that, in your browser you see:
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
3
by: sparks | last post by:
tempname = FindSpaces(rs!) this works fine but if I try to pass a variable value to it For i = 1 To 3 Step 2 tempname = FindSpaces(rs!) why can't the variable i just be used in this way? Is...
3
by: Mrozu | last post by:
Hi How can I include in name of my variable value of other variable? I have following code: For x = 0 To 10 Dim column As New DataGridTextBoxColumn column.MappingName = magazyny(x)
2
by: davey.phillips | last post by:
I have a datagrid within a datagrid which is filled with data from an SQL Server db. Each inner datagrid is populated by an sql statement which contains a variable column name. Output looks...
3
by: chandra.krothapalli | last post by:
Hi, I am writing a program to read database logs using db2Readlog/ db2ReadLogNoConn API. I am able to parse the data of "FIXED format data" and link them to appropriate columns for a given...
3
by: TB | last post by:
On a user control (ascx) I have a datagrid with a hyperlink column containing the following code: <asp:HyperLinkcolumn headerstyle-width="80px" ItemStyle-Width="80px" DataNavigateUrlField="ID"...
1
by: mcolson | last post by:
Is it possible to set a variable in a stored procedure equal to a value from a column when that column's respective ID is equal to max(id)-1 ID A B 1 24 24 2 53 ...
2
by: courbiff | last post by:
Hi everybody I'm wrinting a stored procedure in order to use this last one in a migration script. During the writing i've notice that i have to use a variable in a cursor .. For example ...
2
by: kimmelsd33 | last post by:
I need to read a tab delimited text file in vb6, and store the first column, first line of data in a variable. I need to do the same with the last line, first column of data. This should store a...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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.