The way i display personal information is like this
Code:
<?php
$sql = "SELECT column FROM `table` WHERE `username`= '$name' ";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
while($row = mysql_fetch_assoc($result)) {
$src = '';
switch( $row['column'] ) {
case '0':
$src = 'admin/user.png';
break;
case '1':
$src = 'admin/admin.png';
break;
default:
$src = 'admin/user.png';
}
?><img id="imgcont" src="<?php echo $src; ?>" /><?php
}
?>
this is of course to display images based on a mysql db value.When an account is created it adds a value of ither 0 or 1 to a column in my table. Upon loading if there account has a 0 it will show an image that says user. If it is a 1 it will show an image that says Admin and i also use the same value to allow certain things like control over an admin panel.
you may be wondering how that relates to a single account well it does it all via $name. $name is a variable for a cookie grabbed like so at the head of all my pages
Code:
$name=$_COOKIE["ID_my_site"];
if(isset($_POST['ID_my_site']))
$name=$_POST['ID_my_site'];
and the cookie is set using this code at login.
Code:
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 50400;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
of course once you go into this if you are using sessions you have to switch to checking based on cookies, i prefer cookies and im not really sure how this would work if using sessions so i cant really help you much there.
so if you are not trying to display an image and just a certain accounts information i would do it like this
Code:
<?php
$sql= "SELECT * FROM `table` WHERE `username` = '$name' ";
$result=mysql_query($sql)
{
$row = mysql_fetch_row($result)
{
$WhatEver0 = $row[0];
$WhatEver1 = $row[1];
$WhatEver2 = $row[2];
}
}
?>
*you will have to change this to fit your mysql db*
and than you would display that information in your html by using php echo
Code:
<label for="something"><?php echo $WhatEver0; ?></label>
<input type = "text" id="input1" value="<?php echo $WhatEver1; ?>">
also dont forget to include your db connection that is if your even using a db lol XD
sorry if its a bit confusing
Bookmarks