Re: fetch items from a row [message #181304 is a reply to message #181291] |
Sat, 04 May 2013 10:06 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 03/05/13 22:00, Richard Yates 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'
> ";
>
> But I also wonder why your id numbers in the database are stored as
> strings and not as integer primary keys (which they seem to be).
>
>
It makes no difference. SQL appears to work with either syntax on a
numeric field.
--
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.
|
|
|