Jump to content

Recommended Posts

Ive got this code which works just how i want it to.

 

<? 
$timenow=time();

$select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by id ASC");

$num = mysql_num_rows($select);



?>

 

 

<?=$num?>

 

 

But i want to no how to show 5 users recently online rather the number example

"short3,bullet,ghost rider where online recently"

Without knowing the structure of your database, there isn't an exact solution anyone can give you. You're selecting all the columns from the table, so perhaps something like this will work:

 

<?php
$start = TRUE;
while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  $start = FALSE;
}
else
  echo ', '.$online_array['username'];
}
echo ' were online recently';
?>

You No with This

 

            <?php
$start = TRUE;
while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'],$online_array['image'];
  $start = FALSE;
}
else
  echo ', '.$online_array['username'];
}
echo ' were online recently';
?>	

 

this works but how can i put the .$online_array['image']; into a <img src="">

no tht didnt work i`ll show you the whole script so you can see exactly all of it

 

<?php

session_start();



include_once"includes/db_connect.php";

if (strip_tags($_GET['logout']) == "yes")

{

  session_destroy();

}



if ( isset($_COOKIE['cookname']) )

{

  $_SESSION['username'] = $_COOKIE['cookname'];

  header('Location: authenticated.php');

}

else if ( $_SESSION['username'] )

{

  header('Location: authenticated.php');

}



if (strip_tags($_POST['username']) && strip_tags($_POST['password'])){

$username = addslashes(strip_tags($_POST['username']));

$password = addslashes(strip_tags($_POST['password']));



$ip = $REMOTE_ADDR;



///check INFO

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1");



$login_check = mysql_num_rows($sql);

$inf = mysql_fetch_object($sql);

if ($login_check == "0"){

$message="You could not be logged in";

}elseif ($login_check != "0"){





if ($login_check > "0"){

if ($inf->status == "Dead"){

include_once"dead.php";

exit();



}

if ($inf->status == "Banned"){

$encoded=md5(strtolower($username));

header("Location: banned.php?banned=$username&encoded=$encoded");

exit();

}



if (isset($_POST['remember']))

{

  setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");

}



session_register('username');

$_SESSION['username'] = $inf->username;



$timestamp = time()+60;

mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");

mysql_query("UPDATE users SET l_ip='$ip' WHERE username='$username'");



header("Location: authenticated.php");

} else {

    $message= "You could not be logged in.<br />";

}}



}



$timenow=time();

$select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by id ASC");

$num = mysql_num_rows($select);



?>
<link href="includes/in.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #535353;
}
.style10 {
font-size: 10px;
font-family: Verdana;
}
.style12 {font-size: 14px}
.style13 {font-family: Verdana}
.style15 {font-size: 10px; font-family: Verdana; color: #FFFFFF; }
.style18 {color: #FF3300}
-->
</style></head>

<body>
<form action="?" method="POST">

<table width="800" height="725" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
  <td  height="44" colspan="6" align="left" bgcolor="#222222"><table width="100%" height="59" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
  <td  height="60" colspan="5" align="right" valign="middle" bgcolor="#222222"><br>
    Username:
    
    <input type="text" value="" id="username" class="text_box" name="username"/>
    Password:
    
    <input type="password" value="" id="password" class="text_box" name="password"/>
    <br>
    Remember My Details
    
    <input type="checkbox" id="remember" name="remember" value="1" /></td>
  <td width="90"  height="59" align="center" valign="middle" bgcolor="#222222"> <input type="image" id="loginbtn" src="images/engines.jpg" name="login" value="Login" />	  </td>
      </tr>
  </table>	  </td>
      </tr>
      <tr>
        <td height="32" colspan="5"><img src="images/qick.jpg" alt="" /></td>
      </tr>
      <tr>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="register.php"><img src="login/register.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="lostpassword.php"><img src="login/lostpassword.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="faq.php"><img src="login/faq.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><img src="login/screenshots.jpg" width="160" height="30"></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="contactus.php"><img src="login/contactus.jpg" width="160" height="30" border="0"></a></td>
      </tr>
      <tr>
        <td height="509" colspan="4" align="center" valign="top" bgcolor="#333333"><blockquote>
          <p align="left" class="style12"><br>
            <span class="style13">Welcome To Quick-Shift </span></p>
          <p align="left"><span class="style10">Quickshift is a online game in which any one can play it is a text based game. You start with nothing and work your way to the top the main aim of the game is respect and collect cars and money along the way. You can play the way you want and customize your own profile. Please read the terms of service! </span></p>
          <p align="left" class="style10">Any one can play the game with a internet connection and a email. </p>
          <p align="left"><span class="style15"><span class="style18">There Are Currently 
              </span>
            <?=$num?> 

          <span class="style18">Players Online Right Now. Login or Register To Join Them Now.</span></span><br>
            <br>
            <?php
$start = TRUE;
while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  echo <img src='".$online_array['image']."' />;


  $start = FALSE;
}}
else
  echo  ', '.$online_array['username'];
}
echo ' were online recently';
?>		
          </p>
          </blockquote></td>
        <td height="509" align="center" valign="bottom" bgcolor="#333333"><img src="login/windows.jpg"></td>
      </tr>
      <tr>
        <td colspan="5" align="center" valign="middle" bgcolor="#222222">Home | Register | Lost Password | FAQ | Screen Shots | Contact Us<br>
        Website Coded And Designed By Breathless Visions! </td>
      </tr>
</table>
</form>

oh. usually when you have parse errors, especially with something that is labeled unexpected, you are either missing something (like a semi colon, or a curly bracket) or have to many of something

while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  echo <img src='".$online_array['image']."' />;


  $start = FALSE;
}
}
else notice something missing here
  echo  ', '.$online_array['username'];
}//that should match with this bracket here?
echo ' were online recently';

I tried this

 

<?php

session_start();



include_once"includes/db_connect.php";

if (strip_tags($_GET['logout']) == "yes")

{

  session_destroy();

}



if ( isset($_COOKIE['cookname']) )

{

  $_SESSION['username'] = $_COOKIE['cookname'];

  header('Location: authenticated.php');

}

else if ( $_SESSION['username'] )

{

  header('Location: authenticated.php');

}



if (strip_tags($_POST['username']) && strip_tags($_POST['password'])){

$username = addslashes(strip_tags($_POST['username']));

$password = addslashes(strip_tags($_POST['password']));



$ip = $REMOTE_ADDR;



///check INFO

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1");



$login_check = mysql_num_rows($sql);

$inf = mysql_fetch_object($sql);

if ($login_check == "0"){

$message="You could not be logged in";

}elseif ($login_check != "0"){





if ($login_check > "0"){

if ($inf->status == "Dead"){

include_once"dead.php";

exit();



}

if ($inf->status == "Banned"){

$encoded=md5(strtolower($username));

header("Location: banned.php?banned=$username&encoded=$encoded");

exit();

}



if (isset($_POST['remember']))

{

  setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");

}



session_register('username');

$_SESSION['username'] = $inf->username;



$timestamp = time()+60;

mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");

mysql_query("UPDATE users SET l_ip='$ip' WHERE username='$username'");



header("Location: authenticated.php");

} else {

    $message= "You could not be logged in.<br />";

}}



}



$timenow=time();

$select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by id ASC");

$num = mysql_num_rows($select);



?>
<link href="includes/in.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #535353;
}
.style10 {
font-size: 10px;
font-family: Verdana;
}
.style12 {font-size: 14px}
.style13 {font-family: Verdana}
.style15 {font-size: 10px; font-family: Verdana; color: #FFFFFF; }
.style18 {color: #FF3300}
-->
</style></head>

<body>
<form action="?" method="POST">

<table width="800" height="725" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
  <td  height="44" colspan="6" align="left" bgcolor="#222222"><table width="100%" height="59" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
  <td  height="60" colspan="5" align="right" valign="middle" bgcolor="#222222"><br>
    Username:
    
    <input type="text" value="" id="username" class="text_box" name="username"/>
    Password:
    
    <input type="password" value="" id="password" class="text_box" name="password"/>
    <br>
    Remember My Details
    
    <input type="checkbox" id="remember" name="remember" value="1" /></td>
  <td width="90"  height="59" align="center" valign="middle" bgcolor="#222222"> <input type="image" id="loginbtn" src="images/engines.jpg" name="login" value="Login" />	  </td>
      </tr>
  </table>	  </td>
      </tr>
      <tr>
        <td height="32" colspan="5"><img src="images/qick.jpg" alt="" /></td>
      </tr>
      <tr>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="register.php"><img src="login/register.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="lostpassword.php"><img src="login/lostpassword.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="faq.php"><img src="login/faq.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><img src="login/screenshots.jpg" width="160" height="30"></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="contactus.php"><img src="login/contactus.jpg" width="160" height="30" border="0"></a></td>
      </tr>
      <tr>
        <td height="509" colspan="4" align="center" valign="top" bgcolor="#333333"><blockquote>
          <p align="left" class="style12"><br>
            <span class="style13">Welcome To Quick-Shift </span></p>
          <p align="left"><span class="style10">Quickshift is a online game in which any one can play it is a text based game. You start with nothing and work your way to the top the main aim of the game is respect and collect cars and money along the way. You can play the way you want and customize your own profile. Please read the terms of service! </span></p>
          <p align="left" class="style10">Any one can play the game with a internet connection and a email. </p>
          <p align="left"><span class="style15"><span class="style18">There Are Currently 
              </span>
            <?=$num?> 

          <span class="style18">Players Online Right Now. Login or Register To Join Them Now.</span></span><br>
            <br>
            <?php
$start = TRUE;
while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  echo <img src='"$online_array['image']."' />;


  $start = FALSE;
}
}
  echo ', '.$online_array['username'];
  echo <img src='".$online_array['image']."' />;
}
}
echo ' were online recently';

?>		
          </p>
          </blockquote></td>
        <td height="509" align="center" valign="bottom" bgcolor="#333333"><img src="login/windows.jpg"></td>
      </tr>
      <tr>
        <td colspan="5" align="center" valign="middle" bgcolor="#222222">Home | Register | Lost Password | FAQ | Screen Shots | Contact Us<br>
        Website Coded And Designed By Breathless Visions! </td>
      </tr>
</table>
</form>

 

and get

 

Parse error: syntax error, unexpected '<' in /hosted/subs/ulmb.com/s/t/streetracerz/public_html/index.php on line 213

 

I tried adding and taking brackets away im sorry for your troubles but beleieve me you are helping

wait i got it this works but show 2 of the same person.

 

<?php

session_start();



include_once"includes/db_connect.php";

if (strip_tags($_GET['logout']) == "yes")

{

  session_destroy();

}



if ( isset($_COOKIE['cookname']) )

{

  $_SESSION['username'] = $_COOKIE['cookname'];

  header('Location: authenticated.php');

}

else if ( $_SESSION['username'] )

{

  header('Location: authenticated.php');

}



if (strip_tags($_POST['username']) && strip_tags($_POST['password'])){

$username = addslashes(strip_tags($_POST['username']));

$password = addslashes(strip_tags($_POST['password']));



$ip = $REMOTE_ADDR;



///check INFO

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1");



$login_check = mysql_num_rows($sql);

$inf = mysql_fetch_object($sql);

if ($login_check == "0"){

$message="You could not be logged in";

}elseif ($login_check != "0"){





if ($login_check > "0"){

if ($inf->status == "Dead"){

include_once"dead.php";

exit();



}

if ($inf->status == "Banned"){

$encoded=md5(strtolower($username));

header("Location: banned.php?banned=$username&encoded=$encoded");

exit();

}



if (isset($_POST['remember']))

{

  setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");

}



session_register('username');

$_SESSION['username'] = $inf->username;



$timestamp = time()+60;

mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");

mysql_query("UPDATE users SET l_ip='$ip' WHERE username='$username'");



header("Location: authenticated.php");

} else {

    $message= "You could not be logged in.<br />";

}}



}



$timenow=time();

$select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by id ASC");

$num = mysql_num_rows($select);



?>
<link href="includes/in.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #535353;
}
.style10 {
font-size: 10px;
font-family: Verdana;
}
.style12 {font-size: 14px}
.style13 {font-family: Verdana}
.style15 {font-size: 10px; font-family: Verdana; color: #FFFFFF; }
.style18 {color: #FF3300}
-->
</style></head>

<body>
<form action="?" method="POST">

<table width="800" height="725" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
  <td  height="44" colspan="6" align="left" bgcolor="#222222"><table width="100%" height="59" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
  <td  height="60" colspan="5" align="right" valign="middle" bgcolor="#222222"><br>
    Username:
    
    <input type="text" value="" id="username" class="text_box" name="username"/>
    Password:
    
    <input type="password" value="" id="password" class="text_box" name="password"/>
    <br>
    Remember My Details
    
    <input type="checkbox" id="remember" name="remember" value="1" /></td>
  <td width="90"  height="59" align="center" valign="middle" bgcolor="#222222"> <input type="image" id="loginbtn" src="images/engines.jpg" name="login" value="Login" />	  </td>
      </tr>
  </table>	  </td>
      </tr>
      <tr>
        <td height="32" colspan="5"><img src="images/qick.jpg" alt="" /></td>
      </tr>
      <tr>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="register.php"><img src="login/register.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="lostpassword.php"><img src="login/lostpassword.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="faq.php"><img src="login/faq.jpg" width="160" height="30" border="0"></a></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><img src="login/screenshots.jpg" width="160" height="30"></td>
        <td width="160" height="30" align="center" bgcolor="#333333"><a href="contactus.php"><img src="login/contactus.jpg" width="160" height="30" border="0"></a></td>
      </tr>
      <tr>
        <td height="509" colspan="4" align="center" valign="top" bgcolor="#333333"><blockquote>
          <p align="left" class="style12"><br>
            <span class="style13">Welcome To Quick-Shift </span></p>
          <p align="left"><span class="style10">Quickshift is a online game in which any one can play it is a text based game. You start with nothing and work your way to the top the main aim of the game is respect and collect cars and money along the way. You can play the way you want and customize your own profile. Please read the terms of service! </span></p>
          <p align="left" class="style10">Any one can play the game with a internet connection and a email. </p>
          <p align="left"><span class="style15"><span class="style18">There Are Currently 
              </span>
            <?=$num?> 

          <span class="style18">Players Online Right Now. Login or Register To Join Them Now.</span></span><br>
            <br>
            <?php
$start = TRUE;
while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  echo "<img src='".$online_array['image']."' />";


  $start = FALSE;

}
  echo ', '.$online_array['username'];
  echo "<img src='".$online_array['image']."' />";

}
echo ' were online recently';

?>		
          </p>
          </blockquote></td>
        <td height="509" align="center" valign="bottom" bgcolor="#333333"><img src="login/windows.jpg"></td>
      </tr>
      <tr>
        <td colspan="5" align="center" valign="middle" bgcolor="#222222">Home | Register | Lost Password | FAQ | Screen Shots | Contact Us<br>
        Website Coded And Designed By Breathless Visions! </td>
      </tr>
</table>
</form>

because of this snippet

while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  echo "<img src='".$online_array['image']."' />";


  $start = FALSE;

}
  echo ', '.$online_array['username'];
  echo "<img src='".$online_array['image']."' />";

}

let me quess. the first name is repeated twice?

 

it should be

while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'];
  echo "<img src='".$online_array['image']."' />";


  $start = FALSE;

}
else {
  echo ', '.$online_array['username'];
  echo "<img src='".$online_array['image']."' />";
}

}

 

I suggest reading some tutorials on basic PHP syntax, because these errors are painfully obvious if you are aware of how php works syntactically

Just wanted to point out, mikesta707's earlier suggestion of including brackets around the else is NOT necessary. When brackets are left out, the else is interpreted for 1 following line.

 

Your code could work fine as I suggested it, to add the image, do this:

 

<?php
$start = TRUE;
while ($online_array = mysql_fetch_assoc($select)) {
if ($start) {
  echo $online_array['username'].' <img src="'.$online_array['image'].'" />';
  $start = FALSE;
}
else
  echo ', '.$online_array['username'].' <img src="'.$online_array['image'].'" />';
}
echo ' were online recently';
?>

 

If you want to limit the number of displayed users without limiting the count on the total users, drop off the LIMIT clause in the SELECT statement, and change my above loop as follows:

 

<?php
$start = TRUE;
$max = ($num > 5) ? 5 : $num; // Replace 5 with the max number of users you want to display
for ($i=0; $i<$max; $i++) {
$online_array = mysql_fetch_assoc($select);
if ($start) {
  echo $online_array['username'].' <img src="'.$online_array['image'].'" />';
  $start = FALSE;
}
else
  echo ', '.$online_array['username'].' <img src="'.$online_array['image'].'" />';
}
echo ' were online recently';
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.