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 #181305 is a reply to message #181302] Sat, 04 May 2013 10:08 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
On 04/05/13 10:56, SwissCheese wrote:
> On 05/03/2013 06:15 PM, Richard Yates wrote:
>> On Fri, 03 May 2013 17:38:08 -0400, Lew Pitcher
>> <lpitcher(at)teksavvy(dot)com> wrote:
>>
>>> 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);
>>
>> Yes, I know about BQ. And yes, certainly, if I were doing it, the
>> input would be validated, etc. But, the poster is clearly struggling
>> with the simplest elements of php/mysql and, to learn that part,
>> needed only the simplest answer to his question.
>>
>
> Not only that but last time I checked, PHP/MySQL still doesn't allow
> multi-statement queries.
>
well it certainly allows the above.


--
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.
[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: Sat Nov 30 19:56:33 GMT 2024

Total time taken to generate the page: 0.04124 seconds