Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Table - show session values

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
How do I show the value of this> $_SESSION['DB6']

In a table <td>here</td>

Thanks
 
I have found that the following is a nice shorthand way:
Code:
<td><?=$_SESSION['DB6'];?></td>
You can also use other ways as sleipnir214 mentioned.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Thanks. Is it safe to output session variables in a table?, could you show me how to use echo and print in a table cell. Reagards
 
Both examples of the same thing:
Code:
<td><? echo $_SESSION['DB6']; ?></td>
<td><? print $_SESSION['DB6']; ?></td>
Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
If you just want to see the session vars for inspection you can use print_r($_SESSION) and embed it into <pre>...</pre> tags.
 
Please tell me why this errors on the line where the session variable is in. I tried removing echo, removing <? tags, put in quotes, removing ; you name it I did it. ?????


<?php

for ($i=1;$i<10;$i++)
if ($_SESSION['DB6'][$i]>0)

echo '<table border="1" width="71%" id="table2">

<tr>
<td width="208"><font face="Arial"><b><td><? print $_SESSION['DB6'][$i]; ?></td>
<td width="213">NEXT&nbsp;</td>
<td>NEXT&nbsp;</td>
</tr>

</table>'

?>


<td></td>
 
You have multiple nested problems here.

First, you're already in an echo statement, so you can't issue a print statement there, too.

Second, even if you could, you're already in PHP-interpretation mode, so the "<?" tags will confuse the parser.

You want to print a string literal, a variable, and another string literal all together in a single statement. The way you do this is by concatenating the three elements together.

[tt]print 'A is the name of ' . $b . ' c-stuff.';[/tt]

Look at what the statement prints:[ol][li]A string literal[/li][li]the value in a variable[/li][li]another string literal[/li][/ol] all string together through concatenation (the "." operator). I could also have done:

[tt]print
'A is the name of ' .
$b .
' c-stuff.';[/tt]

The only difference between my example and your script is that your string literals span multiple lines.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Because you're starting a php block in the middle of an echo statement. I do wish you would take our advice(s) and read up on php if you're having trouble understanding it. I still don't know how you cannot grasp even the simplest methods that should not be all that different than those in VB6. You are echoing (printing, reponse.writing, whatever you want to call it) a string and within that string you're opening a php block, call another printing function and closing the block.... How on earth did you expect that to work. It seems to me you put no effort at all in creating the codes you give us and just expect us to correct you when you're wrong. Now, VB6 has outputting functions, right? VB6 has strings, right? And VB6 has concatenating strings and variables to print out something meaningful, right? So why is this so new to you?
Code:
echo '<table border="1" width="71%" id="table2">
    
    <tr>
        <td width="208"><font face="Arial"><b><td>' . $_SESSION['DB6'][$i] . '</td>
        <td width="213">NEXT&nbsp;</td>
        <td>NEXT&nbsp;</td>
    </tr>
    
</table>'
Now think about it. What did I do? I outputted a string, I stopped the string to include the variable, appended the variable and appended the continuation of the string. No magic here.

Whatever is your for sentence doing there and the table cells after the table itself (outside php block) I won't even dare comment.
 
You have to decide where it is you are printing from you establish at the beggining you are using and echo, that means you are with in PHP, but then in the middle of the strin you go and place delimiters.

[red]<?[/red] print $_SESSION['DB6'][$i]; [red]?>[/red]

Make up your mind.

You are either echoing the whole thing from the beggining or just echoing the variable.

in which case it would be:

Code:
echo "<table...." . $_SESSION['DB6'][$i] . "</td>...";


or
Code:
<table .... <td> <? echo $_SESSION['DB6'][$i]; ?> <td>...

You have to be clear about your scopes, where it is you are writing stuff.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thankyou Olav and Jeff, you did help.




<?php
echo '<table border="1">'; //start table outside the loop

for ($i=1;$i<10;$i++)
if ($_SESSION['QTY'][$i]>0) {

echo "<tr><td>Quantity ".$_SESSION['QTY'][$i]." off</td>"; //<----start row & 1st column
echo "<td>".$_SESSION['PROD'][$i]."</td></tr>"; // <----2nd column & end row
}

echo "</table>"; //end table outside the loop
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top