FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » take two - 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: take two - fetch items from a row. [message #181300 is a reply to message #181298] Sat, 04 May 2013 02:20 Go to previous messageGo to previous message
Richard Yates is currently offline  Richard Yates
Messages: 86
Registered: September 2013
Karma:
Member
On Fri, 3 May 2013 19:54:33 -0400, richard <noreply(at)example(dot)com>
wrote:

> On Fri, 03 May 2013 16:32:59 -0700, Richard Yates wrote:
>
>> On Fri, 3 May 2013 19:02:58 -0400, richard <noreply(at)example(dot)com>
>> wrote:
>>
>>> This code may reside on a page in a line.
>>> < a href="http:www.code.com/gettable.php?number=1">
>>>
>>>
>>> Where I show id=$number, is that the way I want to show it or is there a
>>> beter way?
>>> I want to retrieve the row corresponding to the id number given in the
>>> link.
>>>
>>> <?php
>>>
>>>
>>> $number=$_GET["number"];
>>> if (empty($number)) {$number=1;}
>>> $number=(int)$number;
>>>
>>> // connections code left out intentionally //
>>>
>>>
>>> $result = mysql_query("SELECT id,email FROM people WHERE id = $number");
>>> 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 code does work. There are details about it that could be improved
>> and others made suggestions about in response to your first post. I
>> notice that in this post your id field in the database is assumed to
>> be a number where the last time it seemed to be a string. Do yuou know
>> which it is?
>>
>> Have you learned about validating and sanitizing user input yet?
>
> I am assuming that "id" is an integer since that is how it is in the
> database field.
> the int() function changes the string to an integer so that's no big deal.
>
> As with anything you do, you refine your output as time marches on.
> After all, we all know YOU were born an expert in the field right?

No, i am a (possibly advanced) beginner and I am not sure what your
attitude is about. I've tried out your code and answered your
questions (twice). The (basic) beginner level of your code and
questions implied that a gentle question about input validation was
reasonable. Apparently not.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SoapServer constructor parameters: what is actor uri?
Next Topic: replacing spaces with newline
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 02:44:08 GMT 2024

Total time taken to generate the page: 0.05031 seconds