Brady Magrath Brady Magrath - 6 months ago 16
SQL Question

Convert mqsql_query deprecated

I have come to realise mysql_query is deprecated.
What do I need to do to fix this?
As all of it is MySQL.

Simple fact being I need to recode my whole site before it won't work due to deprecated functions.

if (!$_GET['XID']) {
$mystats = array();
$s = array();
$mystats = mysql_query ("SELECT * FROM `members_personal` WHERE playerid = '{$_SESSION['playerid']}'");
$s = mysql_fetch_array($mystats);
echo '<center><main>Personal stats</main>
<hr width="93%">
<table width = "75%" class = "rounded"><tr><td width=45% valign=top>
' . round_table('700') . '<table class = "vnm-table" width=100% cellspacing=1 cellpadding=3>
<tr bgcolor=#999999><th align="left" width=70%>
<b>Attacking</b>
</th><th width=30%></th></tr>
<tr bgcolor=#DFDFDF>
<td>Attacks won:</td>
<td>' . number_format($s['my_attwon']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Attacks lost:</td>
<td>' . number_format($s['my_attlost']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Attacks stalemated:</td>
<td>' . number_format($s['my_attstale']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Defends won:</td>
<td>' . number_format($s['my_defwon']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Defends lost:</td>
<td>' . number_format($s['my_deflost']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Defends stalemated:</td>
<td>' . number_format($s['my_defstale']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Win/Loss ratio:</td>
<td>';

$attwon = array();
$attlost = array();
$first_number = array();
$second_number = array();
$div_value = array();
$attwon = $s['my_attwon'] + $s['my_defwon'];
$attlost = $s['my_attlost'] + $s['my_deflost'];

$div_value = "0.0";
if ($attlost == 0) {
$attlost = '1';
}
$div_value = $attwon / $attlost;

printf("%01.2f", $div_value);

echo '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Times ran away:</td>
<td>' . number_format($s['my_timesran']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Foes ran away:</td>
<td>' . number_format($s['my_theyran']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Best kill streak:</td>
<td>' . number_format($s['my_beststreak']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Current kill streak:</td>
<td>' . number_format($s['my_currstreak']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Hits:</td>
<td>' . number_format($s['my_hits']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Misses:</td>
<td>' . number_format($s['my_misses']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Total damage made:</td>
<td>' . number_format($s['my_totaldamage']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Best damage made:</td>
<td>' . number_format($s['my_bestdamage']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>One hit kills:</td>
<td>' . number_format($s['my_onehitkill']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Critical hits:</td>
<td>' . number_format($s['my_crithits']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Rounds fired:</td>
<td>' . number_format($s['my_rounds']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Stealth attacks:</td>
<td>' . number_format($s['my_stealths']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Money mugged:</font></td>
<td>$' . number_format($s['my_muggain']) . '</td>
</tr><tr bgcolor=#DFDFDF>
<td>Highest level beaten:</td>
<td>' . number_format($s['my_bestlevel']) . '</td>
</tr><tr bgcolor=#CCCCCC>
<td>Total respect gained:</td>
<td>' . number_format($s['my_respectgain']) . '</td>
</tr>
</table>

Answer

You can do this:

$sql="SELECT * FROM `members_personal` WHERE playerid = '{$_SESSION['playerid']}'";
$mystats = mysqli_query($connection,$sql);
$row = mysqli_fetch_array($mystats,MYSQLI_ASSOC);
Comments