PDA

View Full Version : echo a field


devil_online
08-01-2004, 05:58 PM
Hi, Hi have a table with four fields, name, pass, email, team.
How can I display the information on the page of the team?

Hi have this lines:

echo "<h1>Logged In!</h1>";
echo "Benvindo <b>$_SESSION[username], ja está logado. <a href=\"logout.php\">Logout</a>";
}

But it all displays the username even when I change to $_SESSION[team]

Thanks

Serex
08-02-2004, 12:06 AM
try


echo "<h1>Logged In!</h1>";
echo "Benvindo <b>" . $_SESSION['username'] . ", ja está logado. <a href=\"logout.php\">Logout</a>";

devil_online
08-02-2004, 02:52 AM
no...it displays the information of the username. I wanto to display the information of the team. How can I do it? thanks

AaronW
08-02-2004, 03:14 AM
A table with four fields? You mean like a MySQL table? Or a <table>?

Why you're using the $_SESSION variable to access either is beyond me... If it's a MySQL table, then you'll first have to query it:

<?
mysql_connect ($db[host], $db[username], $db[password]);
mysql_select_db ($db[name]);

$row = mysql_fetch_assoc (mysql_query ("SELECT * FROM <yourtable> WHERE name='{$_SESSION[username]}'"));

...

// Echo the team name
echo $row[team];
?>

By the way, both $array[key] and $array["key"] are allowed. I'm not sure about whether or not there are drawbacks to the unquoted one or not... I like using it though ;) Looks cleaner, especially when using array variables in strings like I did in that query.

missing-score
08-02-2004, 03:21 AM
Not quoting array keys will slow down your script, ideally, you should single quote them every time.

If you are interested, the error that you usually never see but that is thrown when you dont use quotes is:

Notice: Use of undefined constant x - assumed 'x' in c:\apache\htdocs\script.php on line x

Now, if you use 20 non quoted keys in your script, PHP will have to throw that error 20 times.

AaronW
08-02-2004, 03:25 AM
Ah, I remember reading something about that. It's the constant thing. I remember now that it looks for constants before the actual key as a string.

I use double quotes when working with the arrays outside of strings, but don't bother when doing the arrays inside strings like I did above. Far easier to read than $str = "The lazy dog " . $array["verb"] . " over the quick brown fox.";

rswyatt
08-02-2004, 02:26 PM
So - I'm right to assume that what you're saying is $_SESSION["username"] is always preferred for a fast running script. Is this also the same for $_SESSION['username'] (are they one in the same?)

Also - to the originator of the post... You'll have to extract the team name out of the database... then assign it to a session variable.

Then you can use $_SESSION['team'] or whatever you name it.

devil_online
08-02-2004, 03:24 PM
Also - to the originator of the post... You'll have to extract the team name out of the database... then assign it to a session variable.
and how I do that?

I put the code here if there's no incovinience

thanks

devil_online
08-05-2004, 01:45 PM
well i have this code,
function displayLogin(){
global $logged_in;
if($logged_in){
echo "<h1>Logged In!</h1>";
echo "well come <b>$_SESSION[username], your logged. <a href=\"logout.php\">Logout</a>";
}
else{
?>


so, it only displays the username, however how can i display my team? tanks

devil_online
08-07-2004, 02:18 PM
any help?