Publicidad

Resultados 1 al 2 de 2
  1. #1
    [IG] [email protected] Avatar de Puky51
    Ingreso
    27 feb, 14
    Mensajes
    104
    País
    Gracias
    9
    5 gracias en 3 Posts

    Red face PhP barra de estado de jugadores

    Hola, quiero hacer algo como esto, tengo el codigo HTML y la consulta a la base de datos, pero no se como hacer que se rellenen conforme a los usuarios que hay en cada facción
    Código:
    <div class="realm">    <div class="realm_online">
                        <span data-tip="Uptime" class="uptime-count">
                        </span>
    
    
            </div>
    
    
            <div class="realm-bar-wrapper">
                <div class="horde-icon" data-tip="Hordes"></div>
                <div class="realm_bar">
                    <!-- el width indica el relleno de la barra --><div data-tip="Horde" class="realm_bar_fill horde" style="width:50%; height: 14px;">
                        </div>
                        <!-- el width indica el relleno de la barra --><div data-tip="Alliance" class="realm_bar_fill alliance" style="width:50%; height: 14px ;">
                        </div>
                </div>
                <div class="alliance-icon" data-tip="Alliance:"></div>
            </div>
    
    
      </div>

    Código PHP:
    <?php$mysqli = new mysqli("localhost""root""ascent""characters");
                    
    /* verificar la conexión */                if (mysqli_connect_errno()) {                    printf("Conexión fallida: %s\n"mysqli_connect_error());                    exit();                }                if ($result $mysqli->query("SELECT playerFlags=40 FROM characters WHERE playerFlags=40")) {
                    
    /* determinar el número de filas del resultado */                $row_cnt $result->num_rows;
                    
                    
    printf('Hordas: %d <br>',$row_cnt);
                    
    /* cerrar el resultset */                $result->close();            }            if ($alis $mysqli->query("SELECT playerFlags=8 FROM characters WHERE playerFlags=8")) {
                    
    /* determinar el número de filas del resultado */                $row_cnt_ali $alis->num_rows;
                    
                    
    printf('Alianzas: %d',$row_cnt_ali);
                    
    /* cerrar el resultset */                $alis->close();            }
                
    /* cerrar la conexión */            $mysqli->close();

                   
    ?>


    - - - - -Post Actualizado- - - - -

    Después de varios intentos e ideas logre hacerlo, tal ves es la manera más complicada o con mucho código pero funciona, lo hice de la siguiente manera.<br><br>
    Código:
    &lt;div class="realm"&gt;<div>&nbsp; &nbsp; &lt;div class="realm_online"&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span data-tip="Uptime" class="uptime-count"&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/span&gt;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="realm-bar-wrapper"&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="horde-icon" data-tip="Hordes"&gt;&lt;/div&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="realm_bar"&gt;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;?php</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*$host = "127.0.0.1";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $user = "root";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $pw = "ascent";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $db = 'characters';</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $conexion = mysql_connect($host,$user,$pw) or die("Error al conectar: ");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mysql_select_db($db, $conexion);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $query=mssql_query("SELECT count(*) FROM characters WHERE playerFlags='40'", $conexion);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $total_count=mysqli_num_rows($query);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "$total_count";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //$query = "SELECT count(*) AS total FROM characters", $conexion;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result = mysql_query($query);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $values = mysql_fetch_assoc($result);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $num_rows = $values['total'];&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $num_rows;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* $query=mssql_query("SELECT playerFlags FROM 'characters'",$conexion);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $total_count =mysql_num_rows($query);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $total_count ; */</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mysqli = new mysqli("localhost", "root", "ascent", "characters");</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* verificar la conexión */</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mysqli_connect_errno()) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Conexión fallida: %s\n", mysqli_connect_error());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($result = $mysqli-&gt;query("SELECT playerFlags=40 FROM characters WHERE playerFlags=40")) {</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* determinar el número de filas del resultado */</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $row_cnt = $result-&gt;num_rows;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //printf('Hordas: %d &lt;br&gt;',$row_cnt);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //echo "&lt;div style='height:".$row_cnt."px;'";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //echo "&lt;div data-tip='Horde' class='realm_bar_fill horde' style='height:14px; width:".$row_cnt."%;'&gt;&lt;/div&gt;";</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($porcen_hor = $mysqli-&gt;query("SELECT playerFlags FROM characters WHERE playerFlags")) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $row_porcen_hor = $porcen_hor-&gt;num_rows;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $hr = ($row_cnt * 100) / $row_porcen_hor;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;div data-tip='Horde' class='realm_bar_fill horde' style='height:14px; width:".$hr."%;'&gt;&lt;/div&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //printf("porcentaje de alianzas %d",$hr);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* cerrar el resultset */</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result-&gt;close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $porcen_hor-&gt;close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($alis = $mysqli-&gt;query("SELECT playerFlags=8 FROM characters WHERE playerFlags=8")) {</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* determinar el número de filas del resultado */</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $row_cnt_ali = $alis-&gt;num_rows;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// printf('Alianzas: %d',$row_cnt_ali);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($porcen_ali = $mysqli-&gt;query("SELECT playerFlags FROM characters WHERE playerFlags")) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $row_porcen_ali = $porcen_ali-&gt;num_rows;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $pa = ($row_cnt_ali * 100) / $row_porcen_ali;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;div data-tip='Horde' class='realm_bar_fill alliance' style='height:14px; width:".$pa."%;'&gt;&lt;/div&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //printf("porcentaje de alianzas %d",$pa);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* cerrar el resultset */</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $alis-&gt;close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $porcen_ali-&gt;close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* cerrar la conexión */</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mysqli-&gt;close();</div><div><br></div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?&gt;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="alliance-icon" data-tip="Alliance:"&gt;&lt;/div&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</div><div><br></div>&nbsp; &lt;/div&gt;
    <br>

  2.    Publicidad


  3. #2
    Baneado! Avatar de imds
    Ingreso
    16 jul, 14
    Ubicación
    NEW YORK CITY - NY , UNITED STATES
    Mensajes
    35
    País
    Gracias
    5
    2 gracias en 2 Posts

    Re: PhP barra de estado de jugadores

    es sólo crear un código y añadir una cadena para que cambie el porcentaje según el estado del juego:

    En este codigo:
    Código:
    <div class="realm">    <div class="realm_online">
                        <span data-tip="Uptime" class="uptime-count">
                        </span>
    
    
            </div>
    
    
            <div class="realm-bar-wrapper">
                <div class="horde-icon" data-tip="Hordes"></div>
                <div class="realm_bar">
                    <!-- el width indica el relleno de la barra --><div data-tip="Horde" class="realm_bar_fill horde" style="width:50%; height: 14px;">
                        </div>
                        <!-- el width indica el relleno de la barra --><div data-tip="Alliance" class="realm_bar_fill alliance" style="width:50%; height: 14px ;">
                        </div>
                </div>
                <div class="alliance-icon" data-tip="Alliance:"></div>
            </div>
    
    
      </div>

    búsqueda de la línea
    Código:
        <!-- el width indica el relleno de la barra --><div data-tip="Horde" class="realm_bar_fill horde" style="width:50%; height: 14px;">
                        </div>
                        <!-- el width indica el relleno de la barra --><div data-tip="Alliance" class="realm_bar_fill alliance" style="width:50%; height: 14px ;">

    reemplazar:

    width:50%;

    para

    width:<?=$string;?>%;



 

Marcadores

Permisos de publicación

  • No puedes crear nuevos temas
  • No puedes responder temas
  • No puedes subir archivos adjuntos
  • No puedes editar tus mensajes
  •