Page 1 of 1

Online image

Posted: Wed Jan 25, 2012 6:26 pm
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++;
  }
?>

Re: Online image

Posted: Wed Jan 25, 2012 9:30 pm
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

Re: Online image

Posted: Thu Jan 26, 2012 8:40 am
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++;
  }
?>

Re: Online image

Posted: Thu Jan 26, 2012 8:46 am
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.

Re: Online image

Posted: Thu Jan 26, 2012 9:50 am
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++;
  }
?>