This topic is locked

edit v2

2/28/2008 3:22:52 AM
PHPRunner General questions
G
garethp authorDevClub member

Sorry - little bit of help needed again.
I have previously posted the following topic http://www.asprunner.com/forums/index.php?showtopic=7676 and a perfect response was posted. However I have a similar scenario...
I have 2 tables

part with fields partid, description, archive (primary is partid)

transactions with field id, partid, value (primary is id) (partid in the add/edit screen is a lookup on part.partid)
If a user clicks to edit a record in the transactions table I would like to check if part.archive = 1 for the part id selected to be edited. If part.archive = 1 then redirected to tablename_list.php else allow edit of the transaction record.
I have the following code form a similar query from Jane...

global $conn,$strTableName;

if ($_REQUEST["editid1"])

{

$str = "select * from ".$strTableName." where partid=".$_REQUEST["editid1"];

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

if ($data = db_fetch_array($rs))

if ($data["archive"]==1)

{

header("Location: tablename_list.php");

exit();

}

}


I believe I can see that I need to replace $_REQUEST["editid1"] to be the partid of the record selected to be edited but I jsut cant work out what to replace it with! $_REQUEST["editid1"] will select the id from the transaction table and then find no record in the part table.
Really appreciate all help.

J
Jane 2/28/2008

Hi,
try to use this code:

global $conn,$strTableName;

if ($_REQUEST["editid1"])

{

$str = "select * from ".$strTableName." where id=".$_REQUEST["editid1"];

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

if ($data = db_fetch_array($rs))

{

$str2 = "select archive from part where partid=".$data["partid"];

$rs2 = db_query($str2,$conn);

if ($data2 = db_fetch_array($rs2))

if ($data2["archive"]==1)

{

header("Location: tablename_list.php");

exit();

}

}

}

G
garethp authorDevClub member 2/28/2008

Brilliant - thanks for much.