FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » fetch items from a row
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: fetch items from a row [message #181290 is a reply to message #181287] Fri, 03 May 2013 20:47 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
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(at)gmail(dot)com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Hopiing for some leads as to what may be wrong in this code
Next Topic: sql order but move some rows bottom
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 19 21:29:02 GMT 2024

Total time taken to generate the page: 0.05044 seconds