Informational messages are displayed in the chat, the user’s login is shown, the user’s icon (rank) is displayed on the left, the icons are stored in the / rank folder, the database has rang values ​​responsible for the amount of experience gained (needed for increasing the rank) and rang_id with values ​​01 , 05, etc. (responsible for the rank number) How to make the rank icon appear in the message to the left of the login?

 $result = mysql_query ("INSERT INTO `chat` (`login`,`text`,`group`,`id`) VALUES('sys','Пользователь $rank_id <font color=\"yellow\">$login</font> купил подарочную карту <font color=\"red\">$cardName</font>.','0',NULL)"); 

On the user profile page, for example, icons are displayed, implemented there so:

 <tr><td id="lef">Звание:</td><td id="rig"> <?php if ($info['rang'] <= 10) {$limit = 10;echo ("<img src=\"rank/icons_small_01.png\">Новобранец<br>$rang/10"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 10 && $info['rang'] < 30) {$limit = 30;echo ("<img src=\"rank/icons_small_02.png\">Рядовой<br>$rang/50"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 30 && $info['rang'] < 50) {$limit = 50;echo ("<img src=\"rank/icons_small_03.png\">Ефрейтор<br>$rang/50"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 50 && $info['rang'] < 150) {$limit = 150;echo ("<img src=\"rank/icons_small_04.png\">Капрал<br>$rang/150"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 150 && $info['rang'] < 370) {$limit = 370;echo ("<img src=\"rank/icons_small_05.png\">Мастер-капрал<br>$rang/370"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 370 && $info['rang'] < 710) {$limit = 710;echo ("<img src=\"rank/icons_small_06.png\">Сержант<br>$rang/710"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 710 && $info['rang'] < 1230) {$limit = 1230;echo ("<img src=\"rank/icons_small_07.png\">Штаб-сержант<br>$rang/1230"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 1230 && $info['rang'] < 2000) {$limit = 2000;echo ("<img src=\"rank/icons_small_08.png\">Мастер-сержант<br>$rang/2000"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 2000 && $info['rang'] < 2900) {$limit = 2900;echo ("<img src=\"rank/icons_small_09.png\">Первый сержант<br>$rang/2900"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 2900 && $info['rang'] < 4100) {$limit = 4100;echo ("<img src=\"rank/icons_small_10.png\">Сержант-Майор<br>$rang/4100"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 4100 && $info['rang'] < 5700) {$limit = 5700;echo ("<img src=\"rank/icons_small_11.png\">Уорэнт-офицер 1<br>$rang/5700"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 5700 && $info['rang'] < 7600) {$limit = 7600;echo ("<img src=\"rank/icons_small_12.png\">Уорэнт-офицер 2<br>$rang/7600"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 7600 && $info['rang'] < 9800) {$limit = 9800;echo ("<img src=\"rank/icons_small_13.png\">Уорэнт-офицер 3<br>$rang/9800"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 9800 && $info['rang'] < 12500) {$limit = 12500;echo ("<img src=\"rank/icons_small_14.png\">Уорэнт-офицер 4<br>$rang/12500"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 12500 && $info['rang'] < 15600) {$limit = 15600;echo ("<img src=\"rank/icons_small_15.png\">Уорэнт-офицер 5<br>$rang/15600"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 15600 && $info['rang'] < 19200) {$limit = 19200;echo ("<img src=\"rank/icons_small_16.png\">Младший лейтенант<br>$rang/19200"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 19200 && $info['rang'] < 23300) {$limit = 23300;echo ("<img src=\"rank/icons_small_17.png\">Лейтенант<br>$rang/23300"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 23300 && $info['rang'] < 28000) {$limit = 28000;echo ("<img src=\"rank/icons_small_18.png\">Старший лейтенант<br>$rang/28000"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 28000 && $info['rang'] < 33200) {$limit = 33200;echo ("<img src=\"rank/icons_small_19.png\">Капитан<br>$rang/33200"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 33200 && $info['rang'] < 39000) {$limit = 3900;echo ("<img src=\"rank/icons_small_20.png\">Майор<br>$rang/39000"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 39000 && $info['rang'] < 45500) {$limit = 45500;echo ("<img src=\"rank/icons_small_21.png\">Подполковник<br>$rang/45500"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 45500 && $info['rang'] < 52700) {$limit = 52700;echo ("<img src=\"rank/icons_small_22.png\">Полковник<br>$rang/52700"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 52700 && $info['rang'] < 60600) {$limit = 60600;echo ("<img src=\"rank/icons_small_23.png\">Бригадир<br>$rang/60600"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 60600 && $info['rang'] < 69200) {$limit = 69200;echo ("<img src=\"rank/icons_small_24.png\">Генерал-майор<br>$rang/69200"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 69200 && $info['rang'] < 78700) {$limit = 78700;echo ("<img src=\"rank/icons_small_25.png\">Генерал-лейтенант<br>$rang/78700"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 78700 && $info['rang'] < 88900) {$limit = 88900;echo ("<img src=\"rank/icons_small_26.png\">Генерал<br>$rang/88900"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 88900 && $info['rang'] < 100000) {$limit = 100000;echo ("<img src=\"rank/icons_small_27.png\">Маршал<br>$rang/100000"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 100000 && $info['rang'] < 112200) {$limit = 112200;echo ("<img src=\"rank/icons_small_28.png\">Фельдмаршал<br>$rang/112200"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 112200 && $info['rang'] < 125500) {$limit = 125500;echo ("<img src=\"rank/icons_small_29.png\">Командор<br>$rang/125500"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> <?php if ($info['rang'] > 125500){$limit = 125500;echo ("<img src=\"rank/icons_small_30.png\">Генералиссимус"); $pc = ((int)$rang / $limit) * 100; echo '<br><div class="loadbox"><div style="width:' . $pc . '%" id="level2"></div></div>'; } ?> 
  • Implemented in profile awful. We must rewrite everything. For example, you will not see the rank at all if it exactly corresponds to the limit value (100000, for example). But what's stopping you from doing exactly as in the code you provided? It is bad, but it works the same. - Andrewus
  • inserted that piece of code, does not work, if you can, write how to insert correctly - KillerFox
  • This option was still $ result = mysql_query ("INSERT INTO chat ( login , text , group , id ) VALUES ('sys',' User <img onclick = \" ('$ user') \ "src = \" rank /icons_small_$rang.png\"><font color = \ "yellow \"> $ login </ font> bought a gift card <font color = \ "red \"> $ cardName </ font>. ',' 0 ' , NULL) "); - KillerFox

1 answer 1

I propose to create in the database a separate table of ranks "ranks" with the structure

 id ранга (id) | название ранга (rank_name) | минимальное кол-во очков (min_points) | максимальное кол-во очков (max_points) | ссылка на иконку (link_to_png) 

And on the user profile page, request its $info['rang'] rank, referring to the database table with ranks, like this: SELECT link_to_png FROM ranks WHERE min_points < {$info['rang']} AND max_points > {$info['rang']} . The resulting link is saved into a variable and called in the template.

  • And in the default type database, set the minimum and maximum? And what will be the values ​​there? - KillerFox 5:58 pm
  • The structure of the table can be done like this: id: primary (primary) (int (11)) || rank_name: varchar (128) || min_points: varchar (128) || max_points: varchar (128) || link_to_png: varchar (128). And further in the table already add all ranks. - Max
  • Well, I made a table with columns, what next? - KillerFox
  • Fill in the table with all ranks from "Recruit" to "Generalissimo". Run the query, save the result to a variable. On the profile page, call a variable with the result of the query from this table. The meaning of the query is that it returns a link to the icon (link_to_png) for the number of points, which is between the minimum (min_points) and maximum (max_points) for the rank (rank_name) that is added to the table. - Max
  • Can you please write the code with variables and how to fill out what and where in the database - KillerFox