Jump to content

Recommended Posts

im trying to replace the text with an image that matches the data out putted

i can not do it as in the 2nd piece of code (its an example of what i want) and i can not find the info doing a search for the list function

$sql2= "SELECT country, GROUP_CONCAT(name ORDER BY country SEPARATOR '<br>') as name	
 FROM tanks_owned
 where player = '$player'	
 GROUP BY country";
$result2=mysql_query($sql2);

	 while (list($country, $name) = mysql_fetch_row($result2)) {	
	 echo "<div style='width:90px; padding:5px; float:left;'>	
	 <h4><img src='./icon/country/$country.png'></h4>$name
</div>";
}

 

$sql2= "SELECT country, GROUP_CONCAT(name ORDER BY country SEPARATOR '<br>') as name
	 FROM tanks_owned
 where player = '$player'
	 GROUP BY country";
$result2=mysql_query($sql2);

	 	 while (list($country, $name) = mysql_fetch_row($result2)) {
		 echo "<div style='width:90px; padding:5px; float:left;'>
		 <h4><img src='./icon/country/$country.png'></h4><img src="./icon/tank/'.$country.'-'.$name6.'.png"/>
</div>";
}

Link to comment
https://forums.phpfreaks.com/topic/274540-add-image-to-list-array-result/
Share on other sites

this code below works fine. i didnt put the full page code as i dont think its relevent to the problem i have atm.

its part of a page that produces this http://nbn-gaming.co.uk/tab.php

i want to replace the text ($name) with an icon which name is from "$country-$name.png" and i carnt work out where to put <img src="./icon/tank/'.$country.'-'.$name.'.png"/>

 

hope that makes more sense

			 $sql2= "SELECT country, GROUP_CONCAT(name ORDER BY country SEPARATOR '<br>') as name	
					 FROM tanks_owned
					 where player = '$player'	
					 GROUP BY country";
			 $result2=mysql_query($sql2);
			 while (list($country, $name) = mysql_fetch_row($result2)) {

						 echo "<div style='width:90px; padding:5px; float:left;'>	
						 <h4><img src='./icon/country/$country.png'></h4>$name
								 </div>";
			 }

the idea is for players to list what tanks they have in the game so the list will be forever changing.

the page im working on lists what the whole clan has got grouped by the player.

its very close to what i want but i just want to get the icon to replace the text. the icon gives alot of info where as if i use text i need to add 3 more columns per name and as u can see its a tight fit now. my other choice (which i have done allready) is to just have a single column for names but the list is pretty long for some players

this is the only way i know how to do what i want but obviously its very bad to do this.

th 1st chunk off code i posted does nearly what i want apart from add the image where $name is.

i hope this is a better explanation.

 

<?php
$player = $row1['player']; // from a diffrent query. this is nested inside another 1
echo '<div id="container" class="container">';
// get 1st country
echo '<div id="germany" class="block">';
		 $sql = "SELECT * from tanks_owned where player = '$player' and country = 'germany' ";
		 $result=mysql_query($sql);
		 echo '<table border="0">';
		 echo "<td class='imgflag'><img src='./icon/country/germany.png'/></td></tr>";
		 while($row = mysql_fetch_array( $result )) {
				 $name = $row['name'];
				 $country = $row['country'];
		 echo "<tr>";
		 echo "<td class='imgtank'><img src='./icon/tank/".$country."-".$name.".png'/></td>";
		 }
		 echo "</tr></table>";
echo '</div>';
// get next country
echo '<div id="uk" class="block">';
 $sql1 = "SELECT * from tanks_owned where player = '$player' and country = 'uk' ";
 $result1=mysql_query($sql1);
 echo '<table border="0">';
 echo "<td class='imgflag'><img src='./icon/country/uk.png'/></td></tr>";
 while($row1 = mysql_fetch_array( $result1 )) {
	 $name1 = $row1['name'];
	 $country1 = $row1['country'];
 echo "<tr>";
 echo "<td class='imgtank'><img src='./icon/tank/".$country1."-".$name1.".png'/></td>";
 }
 echo "</tr></table>";
echo '</div>';
// get next country
echo '<div id="usa" class="block">';
 $sql2 = "SELECT * from tanks_owned where player = '$player' and country = 'usa' ";
 $result2=mysql_query($sql2);
 echo '<table border="0">';
 echo "<td class='imgflag'><img src='./icon/country/usa.png'/></td></tr>";
 while($row2 = mysql_fetch_array( $result2 )) {
	 $name2 = $row2['name'];
	 $country2 = $row2['country'];
 echo "<tr>";
 echo "<td class='imgtank'><img src='./icon/tank/".$country2."-".$name2.".png'/></td>";
 }
 echo "</tr></table>";
echo '</div>';
// get next country
echo '<div id="france" class="block">';
 $sql3 = "SELECT * from tanks_owned where player = '$player' and country = 'france' ";
 $result3=mysql_query($sql3);
 echo '<table border="0">';
 echo "<td class='imgflag'><img src='./icon/country/france.png'/></td></tr>";
 while($row3 = mysql_fetch_array( $result3 )) {
	 $name3 = $row3['name'];
	 $country3 = $row3['country'];
 echo "<tr>";
 echo "<td class='imgtank'><img src='./icon/tank/".$country3."-".$name3.".png'/></td>";
 }
 echo "</tr></table>";
echo '</div>';
// get next country
echo '<div id="ussr" class="block">';
 $sql4 = "SELECT * from tanks_owned where player = '$player' and country = 'ussr' ";
 $result4=mysql_query($sql4);
 echo '<table border="0">';
 echo "<td class='imgflag'><img src='./icon/country/ussr.png'/></td></tr>";
 while($row4 = mysql_fetch_array( $result4 )) {
	 $name4 = $row4['name'];
	 $country4 = $row4['country'];
 echo "<tr>";
 echo "<td class='imgtank'><img src='./icon/tank/".$country4."-".$name4.".png'/></td>";
 }
 echo "</tr></table>";
echo '</div>';
// get next country

echo '<div id="china" class="block1">';
 $sql5 = "SELECT * from tanks_owned where player = '$player' and country = 'china' ";
 $result5=mysql_query($sql5);
 echo '<table border="0" align="center">';
 echo "<td class='imgflag'><img src='./icon/country/china.png'/></td></tr>";
 while($row5 = mysql_fetch_array( $result5 )) {
	 $name5 = $row5['name'];
	 $country5 = $row5['country'];
 echo "<tr>";
 echo "<td class='imgtank'><img src='./icon/tank/".$country5."-".$name5.".png'/></td>";
 }
 echo "</tr></table>";
echo '</div>';	
echo '</div>';
?>

You just need the one query (I'm sure Jessica gave a similar solution but for it's lost in another thread as you started this one)

 

$player = $row1['player']; // from a diffrent query. this is nested inside another 1
echo '<div id="container" class="container">';

$sql = "SELECT country, name
    FROM tanks_owned
    WHERE player = '$player'
    ORDER BY country, name";
$res = mysql_query($sql);
$prev='';

while (list($country, $name) = mysql_fetch_row($res)) {
   if ($country != $prev) {
    if ($prev) {
	    echo "</table></div>\n"; // close previous block
    }
    echo '<div id="$country" class="block">';
    echo '<table border="0">';
    echo "<tr><td class='imgflag'><img src='./icon/country/{$country}.png'/></td></tr>\n";
    $prev = $country;
   }
   echo "<tr><td class='imgtank'><img src='./icon/tank/{$country}-{$name}.png'/></td>\n";
}
echo "</table></div>\n"; // close final block

echo "</div>\n"

once again massive thx barand.

if u ever get to coventry ill buy u a few pints.

 

this is the working page. its to be included into another page and just needs tarting up.

http://nbn-gaming.co.uk/garagetab.php

 

all the info i could find on tab panels said what i done couldnt be done lol.

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.