hyster Posted February 15, 2013 Share Posted February 15, 2013 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>"; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 Uhm, what? Your second set of code has a basic syntax error, as shown by the code highlighting. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 15, 2013 Share Posted February 15, 2013 Where does $name6 come from? BTW why do GROUP_CONCAT(name ORDER BY country ...) ? All the names will be for the same country Quote Link to comment Share on other sites More sharing options...
hyster Posted February 15, 2013 Author Share Posted February 15, 2013 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>"; } Quote Link to comment Share on other sites More sharing options...
Barand Posted February 15, 2013 Share Posted February 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
hyster Posted February 15, 2013 Author Share Posted February 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
hyster Posted February 16, 2013 Author Share Posted February 16, 2013 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>'; ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted February 16, 2013 Share Posted February 16, 2013 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" Quote Link to comment Share on other sites More sharing options...
hyster Posted February 16, 2013 Author Share Posted February 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 16, 2013 Share Posted February 16, 2013 if u ever get to coventry ill buy u a few pints. I'll make a detour next time I go to the Cotswolds Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.