473,473 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Variable in select row

I want to Select a field based upon the number the user keys in I want to
retrieve another field from the same record

This is not working. How do I do it? The tricky bit seems to me to be
putting the variavble in the select quotes.

$scfchknum=$_POST['scfchknum'];
(inlogging mysql)
$upgcollect='SELECT scfpwd1 FROM scfmforening WHERE scfmnum = $scfchknum';
(logout mysql)
$pwd1=mysql_query($upgcollect);
mysql_close();
echo $pwd1;

$scfchknum is the value of the variable assign to user input
scfmforening is the name of the table
scfmnum is the name of the field I want to search in
scfpwd1 is name of the field I want to retreive from
$upgcollect is the data before it is processed with query
$pwd1 is the data after it is processed.

Greatful for any help.
Garry Jones
Sweden
Oct 8 '06 #1
4 1464

Garry Jones napisal(a):
$upgcollect='SELECT scfpwd1 FROM scfmforening WHERE scfmnum = $scfchknum';
After it $upgcollect containts such string: "SELECT scfpwd1 FROM
scfmforening WHERE scfmnum = $scfchknum". $scfchknum was not changed on
its value. You should have written:

$upgcollect="SELECT scfpwd1 FROM scfmforening WHERE scfmnum =
$scfchknum";
or
$upgcollect='SELECT scfpwd1 FROM scfmforening WHERE scfmnum =
'.$scfchknum;

Oct 8 '06 #2
"Mateusz Markowski" <ma*****@bsdmail.orgskrev i meddelandet
news:11**********************@k70g2000cwa.googlegr oups.com...
You should have written:
$upgcollect="SELECT scfpwd1 FROM scfmforening WHERE scfmnum =
$scfchknum";
No, I still can not get this working.

The examples on the net are complex and I can not deduce the simple line of
code that I need from them

This is the problem. Put simply

$var1=$_POST['anum'];
(inlogging mysql)
$var2="SELECT field2 FROM table1 WHERE field4 = $var1";
(logout mysql)
mysql_close();

(Need help with necessary code to assign variable $var2 to the value of
field4 for the record where users value is found)

I can not use the row index as that is assigned to another sequential value
and unknown to the user.

For instance

A table (table1) with the following fields

index, field2, town, townnum

Records of
1 abc dallas 5
2 def denver 3
3 ghh atlanta 17
4 gfe gateshead 24

The user knows the townnumber (5 or 8 or 17 or 24). The user does not know
the index, but townnum will always have a unique value.

He keys in his number.

I then want to look for the value of field 2 in the record where the user's
townnumber was found.

I then want to assign a variable to the value of the field2 in that record

If he types in 3 my code should assign the value of def to $var2

I understand its a combination of select, query and result but need help
with the syntax.

Any help greatly appreciated.

Garry Jones
Sweden



Oct 8 '06 #3
Garry Jones wrote:
"Mateusz Markowski" <ma*****@bsdmail.orgskrev i meddelandet
news:11**********************@k70g2000cwa.googlegr oups.com...

>>You should have written:

>>$upgcollect="SELECT scfpwd1 FROM scfmforening WHERE scfmnum =
$scfchknum";


No, I still can not get this working.

The examples on the net are complex and I can not deduce the simple line of
code that I need from them

This is the problem. Put simply

$var1=$_POST['anum'];
(inlogging mysql)
$var2="SELECT field2 FROM table1 WHERE field4 = $var1";
(logout mysql)
mysql_close();

(Need help with necessary code to assign variable $var2 to the value of
field4 for the record where users value is found)

I can not use the row index as that is assigned to another sequential value
and unknown to the user.

For instance

A table (table1) with the following fields

index, field2, town, townnum

Records of
1 abc dallas 5
2 def denver 3
3 ghh atlanta 17
4 gfe gateshead 24

The user knows the townnumber (5 or 8 or 17 or 24). The user does not know
the index, but townnum will always have a unique value.

He keys in his number.

I then want to look for the value of field 2 in the record where the user's
townnumber was found.

I then want to assign a variable to the value of the field2 in that record

If he types in 3 my code should assign the value of def to $var2

I understand its a combination of select, query and result but need help
with the syntax.

Any help greatly appreciated.

Garry Jones
Sweden


Garry,

$var2 is just a string. You have made no call to MySQL.

Once you have the SQL statement, you must pass it to mysql_query() to
query the database. Then check the result (which is a result set, not
the data itself); false indicates an error.

If there is no error, you must call mysql_fetch_array() or
mysql_fetch_result() to retrieve the actual data.

See the PHP manual for more information.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 8 '06 #4
Garry Jones wrote:
A table (table1) with the following fields

index, field2, town, townnum

Records of
1 abc dallas 5
2 def denver 3
3 ghh atlanta 17
4 gfe gateshead 24

The user knows the townnumber (5 or 8 or 17 or 24). The user does not know
the index, but townnum will always have a unique value.

He keys in his number.
Let's say it's in a POST form. So his number will be $_POST['townnum']
I then want to look for the value of field 2 in the record where the user's
townnumber was found.
// ...
$sql = "select field2 from table1 where townnum={$_POST['townnum']}";
$resource = mysql_query($sql);
if (!$resource) {
// something wrong with the query.
// for simplicity sake we just exit with a message
exit('Error in query: ' . mysql_error());
}
I then want to assign a variable to the value of the field2 in that record
If he types in 3 my code should assign the value of def to $var2
if (mysql_num_rows($resource) == 1) {
$var2 = mysql_result($resource, 0);
} else {
// Either $_POST['townnum'] does not exist, or it is not unique
// anyway, for simplicity sake, we exit with a message
exit('Invalid townnum. Go back and try again.');
}
// no more need for the resource
mysql_free_result($resource);
// ...
// $var2 is now the corresponding value from table1
--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 8 '06 #5

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

Similar topics

1
by: Dennis Westermann | last post by:
I have the following problem XML-File: <SEARCH> <TAG>'x' or 'y'</TAG> </SEARCH> <CHARLIST> <CHAR>a</CHAR> <CHAR>x</CHAR>
3
by: Son KwonNam | last post by:
The title is quite ambiguos. Any way let me explain. In java, the following is possible. ---- String str = ""; for (int i=0; i < 10; i++) { str = str + i; } ----
2
by: Bradford | last post by:
Question for the masses... Lets say I have variable with the following contents "aaaa bbbb ccccc dddd". The format is not specific and the space delimiter could be changed to any other. How...
4
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
2
by: Jon Martin Solaas | last post by:
Hi, I have a general document somewhat like this: -------------------------------------- <root> <level1> <level2> <interestingstuff number="2"/> <interestingstuff number="3"/>...
3
by: Anders Borum | last post by:
Hello! I've come across a strange error that occurs, when you try to return a nodelist from a variable with a choose/where/otherwise statement. I'm not quite sure whether it's a bug or simply...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
3
by: rls03 | last post by:
I have the following which creates a variable containing a relative path where <xsl:value-of select="."/returns a portion of the filename: <xsl:variable...
7
by: Zhang Weiwu | last post by:
Dear all How does javascript realiablily tell if a variable is a reference to an HTML Element "<select>", without causing browser to pop up error message? if (variable.constructor ==...
2
by: Kevin | last post by:
I am having difficulty updating a variable page-time-stamp in the following snippit. The variable time-stamp is initialized from the attribute time-stamp from the log element. Some of the page...
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
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,...
1
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: 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...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.