Re: fetch items from a row [message #181293 is a reply to message #181291] |
Fri, 03 May 2013 21:38 |
Lew Pitcher
Messages: 60 Registered: April 2013
Karma:
|
Member |
|
|
On Friday 03 May 2013 17:00, in comp.lang.php, richard(at)yatesguitar(dot)com
wrote:
> On Fri, 3 May 2013 15:55:58 -0400, richard <noreply(at)example(dot)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"
|
|
|