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 #182452 is a reply to message #181287] Mon, 05 August 2013 00:19 Go 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')?

$_GET isn't a function, it's an associative array.

If you're trying to read the "number" parameter of a get request, you use:

$_GET['number'];

or:

$_GET["number"];

The type of brackets is very important, although in this specific case,
the type of quote marks is less important than it is at other times.

> <?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 ?>

If you only want the email, only request the email.

If you want to output the email address for a specific id number that
comes from a get request, which I think is what you mean:

<?php

$num = 0;

$if isset( $_GET["number"] ) $num = intval( $_GET["number"] );

$sql = "SELECT email FROM people WHERE id = '{$num}'";

$result = mysql_query( sql );

if ( !$result ) {

echo "mysql query \"{$sql}\" failed with: " . mysql_error() . "\n";

} else {

$rows = mysql_num_rows( $result );

if ( $rows != 1 ) {

echo "Unexpected result from sql query \"{$sql}\", {$rows} rows
returned when 1 row expected!\n";

} else {

$row = mysql_fetch_row($result);

if ( $row ) {

echo "Email address is: {$result[0]}\n";

} else {

echo "No email address found for that ID number\n";

}

}

}

--
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: Fri Nov 22 02:59:26 GMT 2024

Total time taken to generate the page: 0.04609 seconds