Jump to content

[SOLVED] echo from any row


dachshund

Recommended Posts

hi,

 

how can i change this:

 


if($_SESSION['uid']){
  $userid = $_SESSION['uid'];
  $query = "SELECT username FROM users WHERE userid = '$userid'";
  $result = mysql_query($query);
  list($username) = mysql_fetch_row($result);
  echo "Welcome. \n";
  echo $username;
}else{

 

to:

 


$query = "SELECT * FROM users WHERE userid = '$userid'";

 

so that I can echo something like $rows['email'] as well as $rows['username']

 

thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/170517-solved-echo-from-any-row/
Share on other sites

if($_SESSION['uid']){
  $userid = $_SESSION['uid'];
  $query = "SELECT * FROM users WHERE userid = '$userid'";
  $result = mysql_query($query);
  row = mysql_fetch_assoc($result);
  echo "Welcome. \n";
  echo $row['username']."\n";
  echo "Your email is ".$row['email'];
}else{

if($_SESSION['uid']){
  $userid = $_SESSION['uid'];
  $query = "SELECT username FROM users WHERE userid = '$userid'";
  $result = mysql_query($query);
  while ($row = mysql_fetch_assoc($result) {
      $username = $row['userid'];
      $email       = $row['email'];
  echo "Welcome. \n";
  echo "$username and $email";
} 
}else{

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.