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
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Jun 29, 2005 3:27 am
Any idea on how I could merge the following functions ?
Code: Select all
function view($stockId) {
if (!$stockId) { echo "<script language=\"javascript\">alert('Selection required')</script>"; }
else {
echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewFaceStock&stockId=".$stockId."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
}
function viewLiners($linerId) {
if (!$linerId) { echo "<script language=\"javascript\">alert('Selection required')</script>"; }
else {
echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewLiner&linerId=".$linerId."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
}
function viewAdhesives($adhesiveId) {
if (!$adhesiveId) { echo "<script language=\"javascript\">alert('Selection required')</script>"; }
else {
echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewAdhesive&adhesiveId=".$adhesiveId."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
}
tia, Will./
djot
Forum Contributor
Posts: 313 Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:
Post
by djot » Wed Jun 29, 2005 3:54 am
Code: Select all
function ($action, $data)
{
if ( (empty($action) OR (empty($data) )
{
echo "<script language=\"javascript\">alert('Selection required')</script>";
}
else
{
switch ($action)
{
case "viewFaceStock": $url_data="&stockId=".$data;
case "viewLiner": $url_data="&linerId=".$data;
case "viewAdhesive": $url_data="&adhesiveId=".$data;
}
echo "<script language=\"javascript\">var newWindow = window.open ('".$_SERVER['PHP_SELF']."?action=".$action.$url_data."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
// or return
}
call it like
Code: Select all
MergedFunctions ('viewFaceStock', '1234');
djot
-
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Jun 29, 2005 6:47 am
I'm getting the following error from this code.. Any ideas, it's correct to me..
line 28 :
Code: Select all
if (isset($_POST['viewFaceStock'])) {mergedFunctions($_POST['viewFaceStock','stockId']);}
Parse error: parse error, expecting `']'' in c:\program files\easyphp1-8\www\materialsregister\auaddsummary.php on line 28
Here's the function (slightly tweaked) :
Code: Select all
function mergedFunctions($actioned, $data)
{
if ( (empty($action)) || (empty($data)) )
{
echo "<script language=\"javascript\">alert('Selection required')</script>";
}
else
{
switch ($actioned)
{
case "viewFaceStock": $url_data="&stockId=".$data;
case "viewLiner": $url_data="&linerId=".$data;
case "viewAdhesive": $url_data="&adhesiveId=".$data;
}
echo "<script language=\"javascript\">var newWindow = window.open ('".$_SERVER['PHP_SELF']."?action=".$actioned.$url_data."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
// or return
} tia, will
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Wed Jun 29, 2005 6:52 am
Code: Select all
if (isset($_POST['viewFaceStock'])) {mergedFunctions($_POST['viewFaceStock'],$_POST['stockId']);}
You need to have the variables separate ... $_POST['var1','var2'] is not valid php.
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Jun 29, 2005 7:35 am
excellent.. thanks that corrected the 'calling' of the function..
now the stockId isn't being passed to the popup.
Code: Select all
function popupFunctions($action, $data)
{
$url_data = isset($_GET['url_data']) ? $_GET['url_data'] : '';
if ( (empty($action)) || (empty($data)) )
{
echo "<script language=\"javascript\">alert('Selection required')</script>";
}
else
{
switch ($action)
{
case "viewFaceStock": $url_data="&stockId=".$data;
case "viewLiner": $url_data="&linerId=".$data;
case "viewAdhesive": $url_data="&adhesiveId=".$data;
}
echo "<script language=\"javascript\">var newWindow = window.open ('".$_SERVER['PHP_SELF']."?action=".$action."&".$url_data."=".$data."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
// or return
}
Code: Select all
if (isset($_REQUEST['viewFaceStock'])) {popupFunctions($_REQUEST['viewFaceStock'],$_REQUEST['stockId']);}
Post on the main page :
["stockId"]=>
string(1) "2"
["viewFaceStock"]=>
string(21) "View Face Stock Specs"
Get on the popup (shows the main page again.)
array(1) {
["action"]=>
string(21) "View Face Stock Specs"
}
any ideas? tia, will.