LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   write line using php if statement and sessions? (https://www.linuxquestions.org/questions/programming-9/write-line-using-php-if-statement-and-sessions-442728/)

ati 05-08-2006 05:42 AM

write line using php if statement and sessions?
 
hi all

here are my sessions:

PHP Code:

    $_SESSION['firsttextbox'] = $_POST['firsttextbox'];
    
$_SESSION['checkbox0'] = $_POST['checkbox0'];
    
$_SESSION['checkbox1'] = $_POST['checkbox1'];
    
$_SESSION['checkbox2'] = $_POST['checkbox2'];
    
$_SESSION['checkbox3'] = $_POST['checkbox3'];
    
$_SESSION['checkbox4'] = $_POST['checkbox4'];
    
$_SESSION['checkbox5'] = $_POST['checkbox5'];
    
$_SESSION['checkbox6'] = $_POST['checkbox6'];
    
$_SESSION['checkbox7'] = $_POST['checkbox7'];
    
$_SESSION['checkbox8'] = $_POST['checkbox8'];
    
$_SESSION['checkbox9'] = $_POST['checkbox9'];
    
$_SESSION['checkbox10'] = $_POST['checkbox10'];
    
$_SESSION['checkbox11'] = $_POST['checkbox11'];
    
$_SESSION['checkbox12'] = $_POST['checkbox12'];
    
$_SESSION['checkbox13'] = $_POST['checkbox13'];
    
$_SESSION['checkbox14'] = $_POST['checkbox14'];
    
$_SESSION['checkbox15'] = $_POST['checkbox15'];
    
$_SESSION['checkbox16'] = $_POST['checkbox16'];
    
$_SESSION['checkbox17'] = $_POST['checkbox17'];
    
$_SESSION['checkbox18'] = $_POST['checkbox18'];
    
$_SESSION['checkbox19'] = $_POST['checkbox19'];
    
$_SESSION['checkbox20'] = $_POST['checkbox20'];
    
$_SESSION['checkbox21'] = $_POST['checkbox21'];
    
$_SESSION['checkbox22'] = $_POST['checkbox22'];
    
$_SESSION['checkbox23'] = $_POST['checkbox23'];
    
$_SESSION['checkbox24'] = $_POST['checkbox24'];
    
$_SESSION['checkbox25'] = $_POST['checkbox25'];
    
$_SESSION['checkbox26'] = $_POST['checkbox26'];
    
$_SESSION['checkbox27'] = $_POST['checkbox27'];
    
$_SESSION['checkbox28'] = $_POST['checkbox28'];
    
$_SESSION['checkbox29'] = $_POST['checkbox29'];
    
$_SESSION['radiobutton'] = $_POST['radiobutton'];
    
$_SESSION['radiobutton1'] = $_POST['radiobutton1'];
    
$_SESSION['radiobutton2'] = $_POST['radiobutton2'];
    
$_SESSION['range1'] = $_POST['range1'];
    
$_SESSION['range2'] = $_POST['range2'];
    
//this is using cookies maintain state
    
$_COOKIE['firsttextbox'] = $_POST['firsttextbox'];
    
$_COOKIE['checkbox0'] = $_POST['checkbox0'];
    
$_COOKIE['checkbox1'] = $_POST['checkbox1'];
    
$_COOKIE['checkbox2'] = $_POST['checkbox2'];
    
$_COOKIE['checkbox3'] = $_POST['checkbox3'];
    
$_COOKIE['checkbox4'] = $_POST['checkbox4'];
    
$_COOKIE['checkbox5'] = $_POST['checkbox5'];
    
$_COOKIE['checkbox6'] = $_POST['checkbox6'];
    
$_COOKIE['checkbox7'] = $_POST['checkbox7'];
    
$_COOKIE['checkbox8'] = $_POST['checkbox8'];
    
$_COOKIE['checkbox9'] = $_POST['checkbox9'];
    
$_COOKIE['checkbox10'] = $_POST['checkbox10'];
    
$_COOKIE['checkbox11'] = $_POST['checkbox11'];
    
$_COOKIE['checkbox12'] = $_POST['checkbox12'];
    
$_COOKIE['checkbox13'] = $_POST['checkbox13'];
    
$_COOKIE['checkbox14'] = $_POST['checkbox14'];
    
$_COOKIE['checkbox15'] = $_POST['checkbox15'];
    
$_COOKIE['checkbox16'] = $_POST['checkbox16'];
    
$_COOKIE['checkbox17'] = $_POST['checkbox17'];
    
$_COOKIE['checkbox18'] = $_POST['checkbox18'];
    
$_COOKIE['checkbox19'] = $_POST['checkbox19'];
    
$_COOKIE['checkbox20'] = $_POST['checkbox20'];
    
$_COOKIE['checkbox21'] = $_POST['checkbox21'];
    
$_COOKIE['checkbox22'] = $_POST['checkbox22'];
    
$_COOKIE['checkbox23'] = $_POST['checkbox23'];
    
$_COOKIE['checkbox24'] = $_POST['checkbox24'];
    
$_COOKIE['checkbox25'] = $_POST['checkbox25'];
    
$_COOKIE['checkbox26'] = $_POST['checkbox26'];
    
$_COOKIE['checkbox27'] = $_POST['checkbox27'];
    
$_COOKIE['checkbox28'] = $_POST['checkbox28'];
    
$_COOKIE['checkbox29'] = $_POST['checkbox29'];
    
$_COOKIE['radiobutton'] = $_POST['radiobutton'];
    
$_COOKIE['radiobutton1'] = $_POST['radiobutton1'];
    
$_COOKIE['radiobutton2'] = $_POST['radiobutton2'];
    
$_COOKIE['range1'] = $_POST['range1'];
    
$_COOKIE['range2'] = $_POST['range2']; 

using he if statement and sessions lets i,m trying to write a line according to the value of the session or cookie to an xsl sheet.

here is my xsl using the fwrite:
Code:

fwrite($handle,'<td><xsl:value-of select="bbb"/></td>'."\n");
thats saying to write this line which is for theto display the values in bbb field, how do i make this diffenrent depending the session so it could be any field thats is is the session.

all together i have any fiels do the user could choose bewteen 1-9 fields to be displayid so thats 1-9 lines, can some one please tell me if thats possible.

thanks

s

thanks :injured:

ati 05-08-2006 05:43 AM

i have tried something like this:

but it does nothing
PHP Code:

                if ($_SESSION == "id" ) {
                
fwrite($handle,'<xsl:sort select="id"/>'."\n");
                } 

i also tried this which is something nearly to what im after, i what ever value is the session print it.

PHP Code:

                if ($_SESSION == ($_SESSION  ) {
                
fwrite($handle,'<xsl:sort select=($_SESSION />'."\n");
                } 

that would be idea but not working either, forgive the inclorrect syntac i,m very new to all this.

thanks

graemef 05-08-2006 07:11 AM

I'm not certain I understand what you are trying to do however, it looks as if you have a form with a number of checkboxes. You need to check to see if the checkbox has been set. You can do this as follows:
PHP Code:

if(!isset($_POST['checkbox1'])){ // add some code here} 

The additional code that you add could be code that will store the selected values in a session variable.

ati 05-08-2006 09:40 AM

i have managed to find the solution,
if (isset($_SESSION['checkbox2'])) {
fwrite($handle,'<td><xsl:value-of select="county_UA"/></td>'."\n");
}

if (isset($_SESSION['checkbox3'])) {
fwrite($handle,'<td><xsl:value-of select="pop_code"/></td>'."\n");
}


is it possible to so the same if your using the same value to make a table for example

instead of a static table rows <tr><th>county_UA</th><th>pop_code</th><th>favourite_instrument</th> <th>bbb</th><th>id</th><th>fruit</th><th>prizes</th><th>fguk_code</th>
<th>fgeu_code</th></tr>

you would do if this value is found on the session than print it like this
<th>county_UA</th>, exacly the same solution i found but with the fields.

thanks

graemef 05-08-2006 10:02 AM

Yes you'd want to do something like the following:

PHP Code:

echo "<tr>";
if (isset(
$_SESSION['checkbox1'])){echo "<th>Heading 1</th>";
if (isset(
$_SESSION['checkbox2'])){echo "<th>Heading 2</th>";
if (isset(
$_SESSION['checkbox3'])){echo "<th>Heading 3</th>";
echo 
"</tr>\n"

You can then add a similar loop that will traverse your data (from a database maybe?)

PHP Code:

foreach ($dataList as $row)
{
   echo 
"<tr>";
   if (isset(
$_SESSION['checkbox1'])){echo "<td>$row[0]</td>";
   if (isset(
$_SESSION['checkbox2'])){echo "<td>$row[1]</td>";
   if (isset(
$_SESSION['checkbox3'])){echo "<td>$row[2]</td>";
   echo 
"</tr>\n";



ati 05-08-2006 11:24 AM

hi graemef

thanks for that and ur effort i will try and let you know

ati 05-08-2006 11:57 AM

hi greamf

many many thanks thats working great,

im trying to do something similar this time but with radio buttons

but it would write this value in the xsl:
[HTML]<xsl:sort select="pop_code"/>[/HTML]

but instead of pop_code it will show what ever the user chose out of 20 radiobuttons or choices but it could only by one obviously out of the 20.

here is the php for that:

PHP Code:

$_SESSION['radiobutton'] = $_POST['radiobutton']; 


i had a try but nothing again :(

PHP Code:

if (isset($_SESSION['radiobutton'])) {
fwrite($handle,'<xsl:sort select="pop_code"/>'."\n");


and i,m sure i'll need 20 of those lines if it works, please have a look and let me know if its correct, thanks again for your trouble and time

:newbie:

graemef 05-08-2006 12:46 PM

You idea looks alright, you can do something like this:

PHP Code:

if (isset($_SESSION['radiobutton1']))
   
$sortSelect "pop_code";
elseif (isset(
$_SESSION['radiobutton2']))
   
$sortSelect "push_code";


fwrite($handle,'<xsl:sort select="'.$sortSelect.'"/>'."\n"); 

With this approach you would require one if statement for each radio button. This is not the only way to code it but probably the simplest. Each line will set up the value that will go into formign the xsl, and then you will write the line out to your file.

ati 05-08-2006 02:09 PM

all my buttons have the same id

here they are:

[HTML]<div>
<fieldset>
<legend>Order By Mechanism - (Sortfield)</legend>
<input type="radio" name="radiobutton" value="none" />none
<input type="radio" name="radiobutton" value="id" />id
<input type="radio" name="radiobutton" value="county_UA" />county_UA
<input type="radio" name="radiobutton" value="pop_code" />pop_code
<input type="radio" name="radiobutton" value="favourite_instrument" />favourite_instrument
<input type="radio" name="radiobutton" value="bbb" />bbb
<input type="radio" name="radiobutton" value="id" />id
<input type="radio" name="radiobutton" value="fruit" />fruit
<input type="radio" name="radiobutton" value="prizes" />prizes
<input type="radio" name="radiobutton" value="fguk_code" />fguk_code
<input type="radio" name="radiobutton" value="fgeu_code" />fgeu_code
<br />
<input type="radio" name="radiobutton" value="none" />none
<input type="radio" name="radiobutton" value="id" />id
<input type="radio" name="radiobutton" value="county_UA" />county_UA
<input type="radio" name="radiobutton" value="pop_code" />pop_code
<input type="radio" name="radiobutton" value="favourite_instrument" />favourite_instrument
<input type="radio" name="radiobutton" value="bbb" />bbb
<input type="radio" name="radiobutton" value="id"/>id
<input type="radio" name="radiobutton" value="fruit" />fruit
<input type="radio" name="radiobutton" value="prizes" />prizes
<input type="radio" name="radiobutton" value="fguk_code" />fguk_code
<input type="radio" name="radiobutton" value="fgeu_code" />fgeu_code
</fieldset>
</div[/HTML]

so the code for this should look like this:

PHP Code:

if (isset($_SESSION['radiobutton']))
   
$sortSelect "none";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "id";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "county_UA";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "push_code";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "bbb";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "id";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "fruit";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "prizes";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "fguk_code";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "fgeu_code";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "none";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "id";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "county_UA";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "push_code";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "bbb";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "id";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "fruit";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "prizes";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "fguk_code";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "fgeu_code"

fwrite($handle,'<xsl:sort select="'.$sortSelect.'"/>'."\n"); 


what do you think?

thanks

ati 05-08-2006 02:52 PM

i have tried both exmples and it results like this:

if i use this:

PHP Code:

if (isset($_SESSION['radiobutton']))
   
$sortSelect "none";
elseif (isset(
$_SESSION['radiobutton']))
   
$sortSelect "id";

fwrite($handle,'<xsl:sort select="'.$sortSelect.'"/>'."\n"); 

it results:
[HTML]<xsl:sort select="none"/>[/HTML]

and i use this my big code it produuces all the lines but not one

ati 05-08-2006 03:28 PM

hi

i managed to find the solution for the radiobutton problem thanks for looking
i do have another though and is to do with my first problem,

is to colour the fields from the radio buttons.

so we have these checkboxes to choose the values that we want coloured

here are the check boxes and radio buttons:
[HTML] <fieldset>
<legend>Colours 1</legend>
<input type="radio" name="radiobutton1" value="chocolate" />chocolate
<input type="radio" name="radiobutton1" value="forestgreen" />forestgreen
<input type="radio" name="radiobutton1" value="turquoise" />turquoise
<br />
<input type="checkbox" name="checkbox11" value="county_UA" />county_UA
<input type="checkbox" name="checkbox12" value="pop_code" />pop_code
<input type="checkbox" name="checkbox13" value="favourite_instrument" />favourite_instrument
<input type="checkbox" name="checkbox14" value="bbb" />bbb
<input type="checkbox" name="checkbox15" value="id" />id
<input type="checkbox" name="checkbox16" value="fruit" />fruit
<input type="checkbox" name="checkbox17" value="prizes" />prizes
<input type="checkbox" name="checkbox18" value="fguk_code" />fguk_code
<input type="checkbox" name="checkbox19" value="fgeu_code" />fgeu_cod
</fieldset>[/HTML]

so i want any of those values to be coloured by the above colours, so if you tick county_ua and than choose it will colour forestgreen.

is that clear?

ati 05-08-2006 04:28 PM

@ graemef

here is my other problem

http://www.linuxquestions.org/questi...27#post2236527

graemef 05-08-2006 06:02 PM

If you just want to dispay the selected items in a different colour then break you code into two parts.

1) Select the colour:
PHP Code:

if (isset($_SESSION['radiobutton1']))
{
   if (
$_SESSION['radiobutton1'] == 'Chocolate')
      
$colour "#D2691E";
   elseif (
$_SESSION['radiobutton1'] == 'ForestGreen')
      
$colour "#228B22"

2) Insert the colour into your web page
PHP Code:

echo "<input type="checkbox" name="checkbox11" value="county_UA ";
if (isset(
$_SESSION['checkbox11'])
   echo "
checked ";
echo "
/><FONT COLOR="$colour">county_UA</FONT>


ati 05-09-2006 04:25 AM

hi graemef

i think were close but it didnt work, let me clarify,

so far from the first set of check boxes when the user ticks it writes these lines from this code offcourse using the sessions:

PHP Code:

if (isset($_SESSION['checkbox2'])) {
                        
fwrite($handle,'<th>county_UA</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox3'])) {
                        
fwrite($handle,'<th>pop_code</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox5'])) {
                        
fwrite($handle,'<th>bbb</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox6'])) {
                        
fwrite($handle,'<th>id</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox7'])) {
                        
fwrite($handle,'<th>fruit</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox8'])) {
                        
fwrite($handle,'<th>prizes</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox9'])) {
                        
fwrite($handle,'<th>fguk_code</th>'."\n");
                           }
                if (isset(
$_SESSION['checkbox10'])) {
                        
fwrite($handle,'<th>fgeu_code</th>'."\n");
                                }
                                
fwrite($handle,'</tr>'."\n"); 

in which it produces this:

[HTML]<table id="tab" border="5" >
<tr bgcolor="#9acd32">
<th>county_UA</th>
<th>pop_code</th>
<th>favourite_instrument</th>
<th>bbb</th>
<th>id</th>
<th>fruit</th>
<th>prizes</th>
<th>fguk_code</th>
<th>fgeu_code</th>
</tr>
<xsl:for-each select="newdata/data1">
<tr>
<td><xsl:value-of select="county_UA"/></td>
<td><xsl:value-of select="pop_code"/></td>
<td><xsl:value-of select="favourite_instrument"/></td>
<td><xsl:value-of select="bbb"/></td>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="fruit"/></td>
<td><xsl:value-of select="prizes"/></td>
<td><xsl:value-of select="fguk_code"/></td>
<td><xsl:value-of select="fgeu_code"/></td>
</tr>[/HTML]

that basicaly writes to the xsl file to display the fields and data from the xml. (this works perfect)

but in another set of check boxes that i have that you saw in my last post, i want to give the user the ability to colour the field's rows if they like by the radio buttons and the field that the want coloured.

basicaly this should output some thing like this:
[HTML]<td bgcolor="#ff00fd"><xsl:value-of select="county_UA"/></td>[/HTML]

and i think we are very close as we have an if statement that handle the colour issue is just a matter of fwrite the code approbiatly in the xsl sheet.

is that clearer you think?

thanks again for your help and time:rolleyes:

ati 05-09-2006 04:31 AM

so it need basicaly to look like this:
with out over writing the users first request from the first set of check boxes but just colour the fields that you want coloured.

[HTML]<tr>
<td bgcolor="#ff00fd"><xsl:value-of select="county_UA"/></td>
<td><xsl:value-of select="pop_code"/></td>
<td><xsl:value-of select="favourite_instrument"/></td>
<td><xsl:value-of select="bbb"/></td>
<td><xsl:value-of select="fruit"/></td>
<td><xsl:value-of select="prizes"/></td>
<td><xsl:value-of select="fguk_code"/></td>
<td><xsl:value-of select="fgeu_code"/></td>
</tr>
[/HTML]

no like this because it will double up the fields values

so it will looke like

county_ua
west
west (with colour)

in code will look like:

[HTML]<tr>
<td bgcolor="#ff00fd"><xsl:value-of select="county_UA"/></td>
<td><xsl:value-of select="pop_code"/></td>
<td><xsl:value-of select="favourite_instrument"/></td>
<td><xsl:value-of select="bbb"/></td>
<td><xsl:value-of select="fruit"/></td>
<td><xsl:value-of select="prizes"/></td>
<td><xsl:value-of select="fguk_code"/></td>
<td><xsl:value-of select="fgeu_code"/></td>
</tr>
<tr>

<td bgcolor="#ff00fd"><xsl:value-of select="county_UA"/></td>


</tr>[/HTML]

i dont know how this will be achieved but ur very close and i,m tampering with the code as we speak.

:newbie:


All times are GMT -5. The time now is 09:21 AM.