This topic is locked
[SOLVED]

 Redirect to Record View

7/18/2011 7:50:25 AM
PHPRunner General questions
H
hsan author

On "after record added" I want to setup redirection to "record view page" and display that particular (last entered) record. I have read many instructions in the forum, but cannot make it work. I have this:
global $conn;

$str = "select ID from new_models";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

header("Location: new_models_view.php?editid1=".$data["ID"]);

exit();
I have two problems - first in URL I also have "editid2" which is foreignkey in the record and do not know how to retrieve it.

Secondly, above query does not retrieve newest record ID.
Please help.

C
cgphp 7/18/2011

You don't need to select the last entered id. PHPrunner does the job for you. The following code is what you need in the "after record added" event:

header("Location: new_models_view.php?editid1=".$values['ID']);

exit();
H
hsan author 7/18/2011



You don't need to select the last entered id. PHPrunner does the job for you. The following code is what you need in the "after record added" event:

header("Location: new_models_view.php?editid1=".$values['ID']);

exit();



That is correct if you do not have FK (editid2). With ".$values['ID'])" alone it does show correct ID in the link but there is no editid2, so page is blank. Any idea?

Thanks

C
cgphp 7/18/2011

If the foreign key field is in the saved record (for example you've chosen it from a dropdown):

header("Location: new_models_view.php?editid1=".$values['ID']."&editid2=".$values['foreignkey_field_name']);

exit();
H
hsan author 7/18/2011



If the foreign key field is in the saved record (for example you've chosen it from a dropdown):

header("Location: new_models_view.php?editid1=".$values['ID']."&editid2=".$values['foreignkey_field_name']);

exit();



I Thank you and greatly appreciate your responses! That was it.