Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9235

Re: fetch items from a row

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.php
Subject Re: fetch items from a row
Date 2013-05-03 20:47 +0000
Organization A noiseless patient Spider
Message-ID <km17ou$da$1@dont-email.me> (permalink)
References <8w0ngcjvc3xo$.7xh0lk9pqzs0.dlg@40tude.net>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web