Jump to content


Photo

add image to list array result


  • Please log in to reply
9 replies to this topic

#1 hyster

hyster

    Advanced Member

  • Members
  • PipPipPip
  • 204 posts

Posted 15 February 2013 - 01:26 PM

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>";
}


#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 15 February 2013 - 01:35 PM

Uhm, what?

Your second set of code has a basic syntax error, as shown by the code highlighting.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,171 posts
  • LocationCheshire, UK

Posted 15 February 2013 - 01:37 PM

Where does $name6 come from?

BTW why do GROUP_CONCAT(name ORDER BY country ...) ?

All the names will be for the same country :confused:

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#4 hyster

hyster

    Advanced Member

  • Members
  • PipPipPip
  • 204 posts

Posted 15 February 2013 - 01:49 PM

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>";
				 }


#5 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,171 posts
  • LocationCheshire, UK

Posted 15 February 2013 - 02:01 PM

You could do in the GROUP_CONCAT() but there is a limit of a 1000 characters in a concatenated field. If you have more than about 20 names for a country it would break the bank.

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#6 hyster

hyster

    Advanced Member

  • Members
  • PipPipPip
  • 204 posts

Posted 15 February 2013 - 02:11 PM

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

#7 hyster

hyster

    Advanced Member

  • Members
  • PipPipPip
  • 204 posts

Posted 16 February 2013 - 12:06 AM

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>';
?>


#8 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,171 posts
  • LocationCheshire, UK

Posted 16 February 2013 - 08:30 AM

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"

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#9 hyster

hyster

    Advanced Member

  • Members
  • PipPipPip
  • 204 posts

Posted 16 February 2013 - 10:06 AM

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.

#10 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,171 posts
  • LocationCheshire, UK

Posted 16 February 2013 - 10:56 AM

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


I'll make a detour next time I go to the Cotswolds :)

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com