Need some urgent help for function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Need some urgent help for function

Post by stanleycwb »

Hi everyone,

I need some help from you all.
Im currently experiencing some problems using php functions.

I had a search.php that will display all the records. And there is a link under each record whereby once the user click on the link, there will be a function to capture the unqiue ID of that record and will return the ID into the next form.
Is this possible?

I thought of a code
function getID($ID) {
return $ID
}

does it work?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need some urgent help for function

Post by Benjamin »

The function you wrote will return the value of the variable passed to it if there wasn't a parse error due to a missing semi-colon.
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Need some urgent help for function

Post by stanleycwb »

Okay. But how do I place my function codes into the php file and display into the html file where I can use the returned ID to do other query?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need some urgent help for function

Post by Benjamin »

Are you writing this from scratch? Can you post what you have completed so far and let us know where you are stuck?
cavemaneca
Forum Commoner
Posts: 59
Joined: Sat Dec 13, 2008 2:16 am

Re: Need some urgent help for function

Post by cavemaneca »

First off, when you say records, do you mean a list or array, or is this stored in a database?

for a database you could use something like this:

Code: Select all

[color=#FF8000]// create query and send[/color]
[color=#0000FF]$query[/color] [color=#0080FF]=[/color] [color=#00BF00]"SELECT * FROM `records`"[/color];
[color=#0000FF]$result[/color] [color=#0080FF]=[/color] [color=#0080FF]mysql_query([/color][color=#0000FF]$query[/color][color=#0080FF])[/color];
 
[color=#FF8000]// display results[/color]
[color=#0000BF]if[/color] [color=#0080FF](mysql_num_rows([/color][color=#0000FF]$result[/color][color=#0080FF]) >[/color] [color=#FF0000]0[/color][color=#0080FF]) {[/color]
  [color=#0000BF]while[/color][color=#0080FF]([/color][color=#0000FF]$row[/color] [color=#0080FF]= mysql_fetch_row([/color][color=#0000FF]$result[/color][color=#0080FF])) {[/color]
    [color=#0000BF]echo[/color] [color=#00BF00]'<a href=\"http://www.website.com/"[/color][color=#0080FF].[/color][color=#0000BF]$_SERVER[[/color][color=#00BF00]'PHP_SELF'[/color][color=#0080FF]].[/color][color=#00BF00]"?recordid="[/color][color=#0080FF].[/color][color=#0000FF]$row[[/color][color=#FF0000]0[/color][color=#0000FF]][/color][color=#0080FF].[/color][color=#00BF00]"\">Send Id</a> - '[/color];
    [color=#0000BF]echo[/color] [color=#0000FF]$row[[/color][color=#FF0000]1[/color][color=#0000FF]][/color][color=#0080FF].[/color][color=#00BF00]' - '[/color];
...
    [color=#0000BF]echo[/color] [color=#0000FF]$row[[/color][color=#FF0000]n[/color][color=#0000FF]][/color];
    [color=#0000BF]echo[/color] [color=#00BF00]'<br>'[/color];
  [color=#0080FF]}[/color]
[color=#0080FF]}[/color] [color=#0000BF]else[/color] [color=#0080FF]{[/color]
  [color=#FF8000]// error if results empty[/color]
  [color=#0000BF]echo[/color] [color=#00BF00]"Could Not Find Records"[/color];
[color=#0080FF]}[/color]
Also, this only works where column 1 of records is a unique id. As well, you can change the $_SERVER['PHP_SELF'] to something else if you are going to send this information to a seperate page. As long as this data doesn't need to be "that" secure, this works fine in combination with $_GET['recordid'].
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Re: Need some urgent help for function

Post by stanleycwb »

Hi,

Sorry for the late reply. I currently dun have the code with me. But will post it days later.
Okay, let me explain.

Firstly, I will have a search form where I can search out records. and will display in the format below.

unique id
name
details1
detail2
update

unique id
name
details1
detail2
update

...
....

For a good form design, the update link should link me to a update form page where I can update specially only that record. I had been figuring out and been thinking a php function might be useful in my implementation.

Im also thinking of $_GET['uniqueID']. But I know it could some sort like extract the data from one place to another. But I dun really understand and how to apply it to my logic physically.

I need to know where I should add this code in and most importantly, the logic behind of it.

Many thanks who replied me and and greatly appreciate your help if anyone could assist me and guide me.
Post Reply