Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #9232 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2013-05-03 15:55 -0400 |
| Last post | 2013-05-04 11:05 +0100 |
| Articles | 12 — 9 participants |
Back to article view | Back to comp.lang.php
fetch items from a row richard <noreply@example.com> - 2013-05-03 15:55 -0400
Re: fetch items from a row Salvatore <sal@yojimbo.hack.invalid> - 2013-05-03 20:18 +0000
Re: fetch items from a row Tim Streater <timstreater@greenbee.net> - 2013-05-03 21:49 +0100
Re: fetch items from a row Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-03 20:47 +0000
Re: fetch items from a row Richard Yates <richard@yatesguitar.com> - 2013-05-03 14:00 -0700
Re: fetch items from a row Scott Johnson <noonehome@chalupasworld.com> - 2013-05-03 14:21 -0700
Re: fetch items from a row Lew Pitcher <lpitcher@teksavvy.com> - 2013-05-03 17:38 -0400
Re: fetch items from a row Richard Yates <richard@yatesguitar.com> - 2013-05-03 15:15 -0700
Re: fetch items from a row SwissCheese <swisscheese@cfl.rr.com> - 2013-05-04 05:56 -0400
Re: fetch items from a row The Natural Philosopher <tnp@invalid.invalid> - 2013-05-04 11:08 +0100
Re: fetch items from a row The Natural Philosopher <tnp@invalid.invalid> - 2013-05-04 11:06 +0100
Re: fetch items from a row The Natural Philosopher <tnp@invalid.invalid> - 2013-05-04 11:05 +0100
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-05-03 15:55 -0400 |
| Subject | fetch items from a row |
| Message-ID | <8w0ngcjvc3xo$.7xh0lk9pqzs0.dlg@40tude.net> |
How would I change the '42' value to a string value based upon the value
retrieved from using $_GET('number')?
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // 42
echo $row[1]; // the email value
?>
[toc] | [next] | [standalone]
| From | Salvatore <sal@yojimbo.hack.invalid> |
|---|---|
| Date | 2013-05-03 20:18 +0000 |
| Message-ID | <km162d$j1l$1@yojimbo.hack> |
| In reply to | #9232 |
On 2013-05-03, richard <noreply@example.com> wrote:
>
> How would I change the '42' value to a string value based upon the value
> retrieved from using $_GET('number')?
> [snip]
What do you mean by this? Do you want the value "42" cast as a string?
--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2013-05-03 21:49 +0100 |
| Message-ID | <timstreater-0F52B7.21495203052013@news.individual.net> |
| In reply to | #9233 |
In article <km162d$j1l$1@yojimbo.hack>,
Salvatore <sal@yojimbo.hack.invalid> wrote:
> On 2013-05-03, richard <noreply@example.com> wrote:
> >
> > How would I change the '42' value to a string value based upon the value
> > retrieved from using $_GET('number')?
> > [snip]
>
> What do you mean by this? Do you want the value "42" cast as a string?
More likely:
$result = mysql_query("SELECT id,email FROM people WHERE id = '" .
$_GET['number'] . "'");
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-05-03 20:47 +0000 |
| Message-ID | <km17ou$da$1@dont-email.me> |
| In reply to | #9232 |
On Fri, 03 May 2013 15:55:58 -0400, richard wrote:
> How would I change the '42' value to a string value based upon the value
> retrieved from using $_GET('number')?
>
> <?php $result = mysql_query("SELECT id,email FROM people WHERE id =
> '42'"); if (!$result) {
> echo 'Could not run query: ' . mysql_error();
> exit;
> }
> $row = mysql_fetch_row($result);
>
> echo $row[0]; // 42 echo $row[1]; // the email value ?>
Rephrase the question so it makes some sort of sense.
$_GET is not a function, $_GET('number') is invalid syntax.
$_GET['number'] will return the string from the get request that was
prefixed with "(?|&)number= up to but not including the end of the
request or the next "&" whichever comes first.
If you're trying to use the string value as a numeric value in a query,
then you may not want to put quotes round it in the query string:
select * from table where column = '42'; // looks for a string
select * from table where column = 42; // looks for a number
As the value you get from the request is a string, and the sql command is
a string, you could just copy the string value across, or you could force
it to a number and back in the process, which might be slightly slower,
but would be a lot safer:
num = -1;
if (isset($_GET['number'])) num = intval($_GET['number'])
if ( num > 0 ) {
sql = "select * from table where column = {$num}";
}
else {
// handle invalid number here
}
But all of this presumes that your issue is that you are comparing a
string value with an integer field, and that's why you're not getting the
result you expect - however you really haven't presented enough
information about the problem - and if your issue is a mysql one, perhaps
you need to ask in a mysql group.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-05-03 14:00 -0700 |
| Message-ID | <k198o8lkqakihel5gu8venk2in088k7i5l@4ax.com> |
| In reply to | #9232 |
On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
wrote:
>
>How would I change the '42' value to a string value based upon the value
>retrieved from using $_GET('number')?
>
>
><?php
>$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>if (!$result) {
> echo 'Could not run query: ' . mysql_error();
> exit;
>}
>$row = mysql_fetch_row($result);
>
>echo $row[0]; // 42
>echo $row[1]; // the email value
>?>
Your question is a little confusing. It sounds like you are GETting an
integer and want to use it in the mysql query there the id is stored
as a string in the database.
$number = $_GET['number'];
$result = mysql_query("select id, email from people where id='$number'
";
But I also wonder why your id numbers in the database are stored as
strings and not as integer primary keys (which they seem to be).
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-05-03 14:21 -0700 |
| Message-ID | <km19ip$o9p$1@dont-email.me> |
| In reply to | #9236 |
On 5/3/2013 2:00 PM, Richard Yates wrote:
> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
> wrote:
>
>>
>> How would I change the '42' value to a string value based upon the value
>> retrieved from using $_GET('number')?
>>
>>
>> <?php
>> $result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>> if (!$result) {
>> echo 'Could not run query: ' . mysql_error();
>> exit;
>> }
>> $row = mysql_fetch_row($result);
>>
>> echo $row[0]; // 42
>> echo $row[1]; // the email value
>> ?>
>
> Your question is a little confusing. It sounds like you are GETting an
> integer and want to use it in the mysql query there the id is stored
> as a string in the database.
>
> $number = $_GET['number'];
> $result = mysql_query("select id, email from people where id='$number'
> ";
>
> But I also wonder why your id numbers in the database are stored as
> strings and not as integer primary keys (which they seem to be).
>
>
I am no expert here but in my experience $_GET holds a string from the
URI query no matter the value.
And the MySQL results will return a string as well whether it is as an
integer or string.
I would double check that in the mysql ng.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lpitcher@teksavvy.com> |
|---|---|
| Date | 2013-05-03 17:38 -0400 |
| Message-ID | <57Wgt.41416$YR4.18232@newsfe28.iad> |
| In reply to | #9236 |
On Friday 03 May 2013 17:00, in comp.lang.php, richard@yatesguitar.com
wrote:
> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
> wrote:
>
>>
>>How would I change the '42' value to a string value based upon the value
>>retrieved from using $_GET('number')?
>>
>>
>><?php
>>$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>>if (!$result) {
>> echo 'Could not run query: ' . mysql_error();
>> exit;
>>}
>>$row = mysql_fetch_row($result);
>>
>>echo $row[0]; // 42
>>echo $row[1]; // the email value
>>?>
>
> Your question is a little confusing. It sounds like you are GETting an
> integer and want to use it in the mysql query there the id is stored
> as a string in the database.
>
> $number = $_GET['number'];
> $result = mysql_query("select id, email from people where id='$number'
> ";
Have you met little Bobby Tables (http://xkcd.com/327/) ?
The PHP documentation webpages have a slightly better suggestion for this
sort of query...
From http://www.php.net/manual/en/function.mysql-query.php
// Formulate Query
// This is the best way to perform an SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT firstname, lastname, address, age FROM friends
WHERE firstname='%s' AND lastname='%s'",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname));
// Perform Query
$result = mysql_query($query);
--
Lew Pitcher
"In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-05-03 15:15 -0700 |
| Message-ID | <efd8o8191dv49c5pu0ejrr4nu3nf7c4rol@4ax.com> |
| In reply to | #9238 |
On Fri, 03 May 2013 17:38:08 -0400, Lew Pitcher
<lpitcher@teksavvy.com> wrote:
>On Friday 03 May 2013 17:00, in comp.lang.php, richard@yatesguitar.com
>wrote:
>
>> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
>> wrote:
>>
>>>
>>>How would I change the '42' value to a string value based upon the value
>>>retrieved from using $_GET('number')?
>>>
>>>
>>><?php
>>>$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>>>if (!$result) {
>>> echo 'Could not run query: ' . mysql_error();
>>> exit;
>>>}
>>>$row = mysql_fetch_row($result);
>>>
>>>echo $row[0]; // 42
>>>echo $row[1]; // the email value
>>>?>
>>
>> Your question is a little confusing. It sounds like you are GETting an
>> integer and want to use it in the mysql query there the id is stored
>> as a string in the database.
>>
>> $number = $_GET['number'];
>> $result = mysql_query("select id, email from people where id='$number'
>> ";
>
>Have you met little Bobby Tables (http://xkcd.com/327/) ?
>
>The PHP documentation webpages have a slightly better suggestion for this
>sort of query...
>
>From http://www.php.net/manual/en/function.mysql-query.php
> // Formulate Query
> // This is the best way to perform an SQL query
> // For more examples, see mysql_real_escape_string()
> $query = sprintf("SELECT firstname, lastname, address, age FROM friends
> WHERE firstname='%s' AND lastname='%s'",
> mysql_real_escape_string($firstname),
> mysql_real_escape_string($lastname));
>
> // Perform Query
> $result = mysql_query($query);
Yes, I know about BQ. And yes, certainly, if I were doing it, the
input would be validated, etc. But, the poster is clearly struggling
with the simplest elements of php/mysql and, to learn that part,
needed only the simplest answer to his question.
[toc] | [prev] | [next] | [standalone]
| From | SwissCheese <swisscheese@cfl.rr.com> |
|---|---|
| Date | 2013-05-04 05:56 -0400 |
| Message-ID | <km2lqk$npk$1@dont-email.me> |
| In reply to | #9239 |
On 05/03/2013 06:15 PM, Richard Yates wrote:
> On Fri, 03 May 2013 17:38:08 -0400, Lew Pitcher
> <lpitcher@teksavvy.com> wrote:
>
>> On Friday 03 May 2013 17:00, in comp.lang.php, richard@yatesguitar.com
>> wrote:
>>
>>> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
>>> wrote:
>>>
>>>>
>>>> How would I change the '42' value to a string value based upon the value
>>>> retrieved from using $_GET('number')?
>>>>
>>>>
>>>> <?php
>>>> $result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>>>> if (!$result) {
>>>> echo 'Could not run query: ' . mysql_error();
>>>> exit;
>>>> }
>>>> $row = mysql_fetch_row($result);
>>>>
>>>> echo $row[0]; // 42
>>>> echo $row[1]; // the email value
>>>> ?>
>>>
>>> Your question is a little confusing. It sounds like you are GETting an
>>> integer and want to use it in the mysql query there the id is stored
>>> as a string in the database.
>>>
>>> $number = $_GET['number'];
>>> $result = mysql_query("select id, email from people where id='$number'
>>> ";
>>
>> Have you met little Bobby Tables (http://xkcd.com/327/) ?
>>
>> The PHP documentation webpages have a slightly better suggestion for this
>> sort of query...
>>
>>From http://www.php.net/manual/en/function.mysql-query.php
>> // Formulate Query
>> // This is the best way to perform an SQL query
>> // For more examples, see mysql_real_escape_string()
>> $query = sprintf("SELECT firstname, lastname, address, age FROM friends
>> WHERE firstname='%s' AND lastname='%s'",
>> mysql_real_escape_string($firstname),
>> mysql_real_escape_string($lastname));
>>
>> // Perform Query
>> $result = mysql_query($query);
>
> Yes, I know about BQ. And yes, certainly, if I were doing it, the
> input would be validated, etc. But, the poster is clearly struggling
> with the simplest elements of php/mysql and, to learn that part,
> needed only the simplest answer to his question.
>
Not only that but last time I checked, PHP/MySQL still doesn't allow
multi-statement queries.
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-05-04 11:08 +0100 |
| Message-ID | <km2mls$ngj$3@news.albasani.net> |
| In reply to | #9247 |
On 04/05/13 10:56, SwissCheese wrote:
> On 05/03/2013 06:15 PM, Richard Yates wrote:
>> On Fri, 03 May 2013 17:38:08 -0400, Lew Pitcher
>> <lpitcher@teksavvy.com> wrote:
>>
>>> On Friday 03 May 2013 17:00, in comp.lang.php, richard@yatesguitar.com
>>> wrote:
>>>
>>>> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
>>>> wrote:
>>>>
>>>>>
>>>>> How would I change the '42' value to a string value based upon the
>>>>> value
>>>>> retrieved from using $_GET('number')?
>>>>>
>>>>>
>>>>> <?php
>>>>> $result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>>>>> if (!$result) {
>>>>> echo 'Could not run query: ' . mysql_error();
>>>>> exit;
>>>>> }
>>>>> $row = mysql_fetch_row($result);
>>>>>
>>>>> echo $row[0]; // 42
>>>>> echo $row[1]; // the email value
>>>>> ?>
>>>>
>>>> Your question is a little confusing. It sounds like you are GETting an
>>>> integer and want to use it in the mysql query there the id is stored
>>>> as a string in the database.
>>>>
>>>> $number = $_GET['number'];
>>>> $result = mysql_query("select id, email from people where id='$number'
>>>> ";
>>>
>>> Have you met little Bobby Tables (http://xkcd.com/327/) ?
>>>
>>> The PHP documentation webpages have a slightly better suggestion for
>>> this
>>> sort of query...
>>>
>>> From http://www.php.net/manual/en/function.mysql-query.php
>>> // Formulate Query
>>> // This is the best way to perform an SQL query
>>> // For more examples, see mysql_real_escape_string()
>>> $query = sprintf("SELECT firstname, lastname, address, age FROM
>>> friends
>>> WHERE firstname='%s' AND lastname='%s'",
>>> mysql_real_escape_string($firstname),
>>> mysql_real_escape_string($lastname));
>>>
>>> // Perform Query
>>> $result = mysql_query($query);
>>
>> Yes, I know about BQ. And yes, certainly, if I were doing it, the
>> input would be validated, etc. But, the poster is clearly struggling
>> with the simplest elements of php/mysql and, to learn that part,
>> needed only the simplest answer to his question.
>>
>
> Not only that but last time I checked, PHP/MySQL still doesn't allow
> multi-statement queries.
>
well it certainly allows the above.
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-05-04 11:06 +0100 |
| Message-ID | <km2min$ngj$2@news.albasani.net> |
| In reply to | #9236 |
On 03/05/13 22:00, Richard Yates wrote:
> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply@example.com>
> wrote:
>
>> How would I change the '42' value to a string value based upon the value
>> retrieved from using $_GET('number')?
>>
>>
>> <?php
>> $result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
>> if (!$result) {
>> echo 'Could not run query: ' . mysql_error();
>> exit;
>> }
>> $row = mysql_fetch_row($result);
>>
>> echo $row[0]; // 42
>> echo $row[1]; // the email value
>> ?>
> Your question is a little confusing. It sounds like you are GETting an
> integer and want to use it in the mysql query there the id is stored
> as a string in the database.
>
> $number = $_GET['number'];
> $result = mysql_query("select id, email from people where id='$number'
> ";
>
> But I also wonder why your id numbers in the database are stored as
> strings and not as integer primary keys (which they seem to be).
>
>
It makes no difference. SQL appears to work with either syntax on a
numeric field.
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-05-04 11:05 +0100 |
| Message-ID | <km2mgf$ngj$1@news.albasani.net> |
| In reply to | #9232 |
On 03/05/13 20:55, richard wrote:
> How would I change the '42' value to a string value based upon the value
> retrieved from using $_GET('number')?
$_GET['number'] IIRC...
>
> <?php
> $result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
> if (!$result) {
> echo 'Could not run query: ' . mysql_error();
> exit;
> }
> $row = mysql_fetch_row($result);
>
> echo $row[0]; // 42
> echo $row[1]; // the email value
> ?>
$result = mysql_query("SELECT id,email FROM people WHERE id = '<?echo $_GET['number']?>'");
with usual caveats about SQL injection etc.
I tend to use - sprintf as in
$query=sprintf("SELECT id,email FROM people WHERE id = '%d'"
,$_GET['number'])
$result = mysql_query($query);
to make sure what's in there is only a decimal number.
-- Ineptocracy (in-ep-toc’-ra-cy) – a system of government where the
least capable to lead are elected by the least capable of producing, and
where the members of society least likely to sustain themselves or
succeed, are rewarded with goods and services paid for by the
confiscated wealth of a diminishing number of producers.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web