Jump to content

Newbie PHP Select in Forms


dstaton

Recommended Posts

I am modifying a form from a previous employee.  I am new to PHP and am not sure where to start.  We have an Oracle database that we pull reports from using PHP and SQL.  In the PHP form, I have selections for Channels (each individual channel) and Dates.  I need to add a selection of "All Channels".  I can't figure out how to do that.  Can you please help?  This is a portion of the current form that gives me each individual channel.  How can I add at the bottom of this list of channels the option for "All Channels"?

 

<td class=Header valign=top>Choose Channel(s)</td>

<td class=Header><?

$qry = 'SELECT CHANNEL_CODE,CHANNEL_NAME,RIGHTS_TYPE FROM LAPTV.PRIMARY_CHANNEL_LIST';

$stmt = ociparse($conn,$qry);

              ociexecute($stmt);

              while (OCIFetchInto($stmt,$res,OCI_ASSOC+OCI_RETURN_NULLS)){?>

              <input type=checkbox name="Chan_<?echo $res['CHANNEL_CODE']?>_<?echo $res['RIGHTS_TYPE'];?>" id="Chan_<?echo $res['CHANNEL_CODE']?>_<?echo $res['RIGHTS_TYPE'];?>">

                    <label for="Chan_<?echo $res['CHANNEL_CODE']?>_<?echo $res['RIGHTS_TYPE'];?>"><?echo $res['CHANNEL_NAME'];?></label><br /> <?

              }?>

</td>

Link to comment
https://forums.phpfreaks.com/topic/47883-newbie-php-select-in-forms/
Share on other sites

Hi dstaton

 

Hopefully, I've understood correctly - here goes.......

 

In the code you have supplied, there is a loop running. This starts at the "while" statement and is enclosed with { and }.

 

So, by inserting yoru additional code "outside" this loop - you ensure it is only interated once. Also, assuming you only wish to "hard code" the final "All Channels" option - you can use HTML.

 

So, after the } ?> code at the end (which ends the loop and moves from PHP back to HTML.....

 

<input type=checkbox name="All" id="All"><label for="All Channels">All Channels</label>

 

You can obviously modify the required values of checkbox name etc to suit the code execution when the form is submitted - but, hopefully this gets across the general idea.

Thanks.  That added my "All Channels" selection.  Next problem is that within the actual report process that runs once you make your selections, it stipulates that one channel must be selected.  The "All Channels" doesn't apparently qualify for that.  How can I make the "All Channels" be included as an acceptable "Channel"?

 

$channelselected = false;

foreach ($_POST as $key=>$value){

if (substr($key,0,4) == 'Chan') $channelselected = true;   

}

 

if (!$channelselected){

$errfound = true;

$errstring = 'At least one channel must be selected\n';

}

 

if (!$errfound){

$reportlist = array();

$reportindex = 0;

foreach ($_POST as $key=>$value){

if (substr($key,0,4) == 'Chan'){

$channelcode = substr($key,5,4);

    $channelrights = str_replace('Chan_'.$channelcode.'_','',$key);

$reportindex++;

      $reportlist[$reportindex] = GenerateReport($reportstartdate,$reportenddate,$channelcode,$conn,&$ErrorArray,&$WebServerPath,&$ErrFilePath,&$ErrFileName);

 

Hi there.

 

From the code, it appears that there is a loop running to validate that any selected values begin with the letters CHAN.

 

On line 3 - the code snippet - substr($key, 0, 4) is saying - "evaluate the first 4 characters beginning with charater 0 for the phrase CHAN".

 

I guess you could add an "OR" statement to allow for ALL CHANNELS or alternatively, set the value for All CHannels to "Channels - ALL" (thereby satisfying the evaluation of the 1st 4 characters to = CHAN).

 

To go for option 1 (above) - add the following code "|| substr($key, 0, 12) == "ALL CHANNELS" right after "Chan" on line 3.

To go for option 2 - amend the earlier HTML code so that it reads "<input type=checkbox name="Channels All" id="All"><label for="All Channels">All Channels</label>"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.