Online image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ArmyOps
Forum Newbie
Posts: 3
Joined: Wed Jan 25, 2012 6:01 pm

Online image

Post by ArmyOps »

i made a small script for highscore table, but it aint working as it should be. Any1 can tell me for show me mistakes? or give me advice how should do it?
Whats the problem is, i wanted to make it so, that $row[online] would change to image what will come from echos.
Anyways here is the current code:

Code: Select all

<?php
include('configs.php');
?>
	<table id="silver" summary="Gradient Table" border="1" -moz-border-radius: 20px>
		<thead>
			<tr>
				<th>Koht</th>
				<th>Kasutajanimi</th>
				<th>Online</th>
				<th>Raha</th>
			</tr>
		</thead>
		<tbody>

<?PHP
if($row[Online]=='JAH')
{
	echo ("image-online");
}
else 
{
	echo ("image-offline");
}


$result = mysql_query("SELECT * FROM kasutajad ORDER BY Raha DESC LIMIT 100");

  $i = 1;
  while($row = mysql_fetch_array( $result ) )
  {
    printf( 
			"<tr>
				<td>$i</td>
				<td>");?> <a href="kasutaja.php?id=<?php printf ("$row[kasutaja]"); ?>"><?php printf ("$row[kasutaja]"); ?><?php printf ("</a><td>$row[Online]</td></td>
				<td>$row[Raha]</td>
			</tr>" 
			);
    $i++;
  }
?>
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Online image

Post by twinedev »

First, see this: http://www.php.net/manual/en/language.t ... rray.donts

If you are wanting the image to change per record you read, you would need to put that code in the loop.

You are needlessly using printf when print or echo will do.

Not sure about the other functionality you are needing, but that may get you started.

-Greg

PS, also just noticed your opening <table> tag, which is a complete mess. see http://www.w3schools.com/tags/tag_table.asp
ArmyOps
Forum Newbie
Posts: 3
Joined: Wed Jan 25, 2012 6:01 pm

Re: Online image

Post by ArmyOps »

I dont still get the point what i'l be missing :S I also used quotes but wount take any effect.

Code: Select all


<?PHP
<!---------------------- Code A  Starts -------------------->
<!-- Made the code more simple -->
if($row[Online]=='JAH')
		echo ('image-online');

if($row[Online]=='Ei')
		echo ('image-offline');
<!---------------------- Code A  Ends -------------------->

<!-- Echos pops up here -->

<!-- Code B Starts -->
$result = mysql_query("SELECT * FROM kasutajad ORDER BY Raha DESC LIMIT 100");

  $i = 1;
  while($row = mysql_fetch_array( $result ) )
  {
    echo( 
			"<tr>
				<td>$i</td>
				<td>");?> <a href="kasutaja.php?id=<?php echo ("$row[kasutaja]"); ?>"><?php echo ("$row[kasutaja]"); ?><?php echo ("</a><td>$online</td></td>
				<td>$row[Online]</td> <!-- that row still wount take the echos above, what makes me worry. Echos pops up from top of table, but i actualy wants it to pop up, if the Online row is used in table (here) -->
			</tr>" 
			);
    $i++;
  }
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Online image

Post by Celauran »

Code: Select all

<?PHP
<!---------------------- Code A  Starts -------------------->
<!-- Made the code more simple -->
if($row[Online]=='JAH')
		echo ('image-online');

if($row[Online]=='Ei')
		echo ('image-offline');
<!---------------------- Code A  Ends -------------------->
$row hasn't been defined at this point in the code, so both conditions fail. Even if they didn't, your echo statements would output the words 'image-online' (or -offline) rather than an image, which I think you're expecting.

I've noticed you're also echoing $online farther down the code, but $online has also not been defined.
ArmyOps
Forum Newbie
Posts: 3
Joined: Wed Jan 25, 2012 6:01 pm

Re: Online image

Post by ArmyOps »

Ok i got it work now... Maybe i explained my self a bit difficulty, but my code was actualy correct. I just had to put it in table, under "While"

Code: Select all

<?php
include('configs.php');
?>
        <table id="silver" summary="Gradient Table" border="1" -moz-border-radius: 20px>
                <thead>
                        <tr>
                                <th>Koht</th>
                                <th>Kasutajanimi</th>
                                <th>Online</th>
                                <th>Raha</th>
                        </tr>
                </thead>
                <tbody>

<?PHP
$result = mysql_query("SELECT * FROM kasutajad ORDER BY Raha DESC LIMIT 100");

  $i = 1;
  while($row = mysql_fetch_array( $result ) )
  {
    printf( 
                        "<tr>
                                <td>$i</td>
                                <td>");?> <a href="kasutaja.php?id=<?php printf ("$row[kasutaja]"); ?>"><?php printf ("$row[kasutaja]"); ?><?php printf ("</a><td>$row<!-- CODE COMES HERE --></td></td>
                                <td>$row[Raha]</td>
                        </tr>" 
                        );
    $i++;
  }
?>
Post Reply