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?
Need some urgent help for function
Moderator: General Moderators
-
stanleycwb
- Forum Newbie
- Posts: 23
- Joined: Fri Aug 15, 2008 11:33 am
Re: Need some urgent help for function
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
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?
Re: Need some urgent help for function
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
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:
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'].
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]-
stanleycwb
- Forum Newbie
- Posts: 23
- Joined: Fri Aug 15, 2008 11:33 am
Re: Need some urgent help for function
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.
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.