Re: fetch items from a row [message #181303 is a reply to message #181287] |
Sat, 04 May 2013 10:05 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma:
|
Senior Member |
|
|
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.
|
|
|