Jump to content

[SOLVED] PHP Ignore last zero/s


Minase

Recommended Posts

hy there,i have a problem with a script and i forgot what i did in previous scripts to fix this

a few months ago i was working on a game (got bored,and in this free time i learned more php.i saw that my code was messy,started to write it again,what i did write back then in months,i did write now in 3days  ;D

but i forgot how i did fix this problem:

i do have numbers in database from 1 till 100

my character have an number too,i want to echo all numbers till my character number,if my character number is 70,in a page it will echo numbers from 1 till 70 (no problem at all,easy to do) the bug is that it read just the first 2 digits :|

if my character number is 99 it will see numbers from 1-99 if my character number is 100,it will see numbers from 1-1

if my number is 230 it will read 23

i did use this

function ShowNumber ()
{
	global $db;

	$query1 = "SELECT * FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $_SESSION['user_id'] );
	$user = $db->getRow ( $query1 );

	$query2  = "SELECT * FROM `" . DBPREFIX . "items` WHERE `ShowLvl` <= " . $db->qstr ( $user->Level ) . "AND Kind='Weapon'";
	$result = mysql_query($query2);

	while($item = mysql_fetch_row($result))
	{
	$iid    = $item[0];
	$iname = $item[1];
	$istrenght = $item[2];
	$ipstrenght = $item[3];
	$iagility = $item[4];
	$idefence = $item[5];
	$ipdefence = $item[6];
	$iendurance = $item[7];
	$icharisma = $item[8];
	$ibuy = $item[9];
	$isell = $item[10];
	$ilevel = $item[11];
	$istone = $item[12];
	$ishowlvl = $item[13];
	$ikind = $item[14];
	$iimg = $item[15];
	$idescription = $item[16];

	echo '
	my stuffs';

	} 


}

thank you very much

Link to comment
https://forums.phpfreaks.com/topic/107863-solved-php-ignore-last-zeros/
Share on other sites

	function ShowWeapons ()
{
	global $db;

	$query1 = "SELECT * FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $_SESSION['user_id'] );
	$user = $db->getRow ( $query1 );

	$query2  = "SELECT * FROM `" . DBPREFIX . "items` WHERE `ShowLvl` <= " . $db->qstr ( $user->Level ) . "AND Kind='Weapon'";
	$result = mysql_query($query2);

	while($item = mysql_fetch_row($result))
	{
	$iid    = $item[0];
	$iname = $item[1];
	$istrenght = $item[2];
	$ipstrenght = $item[3];
	$iagility = $item[4];
	$idefence = $item[5];
	$ipdefence = $item[6];
	$iendurance = $item[7];
	$icharisma = $item[8];
	$ibuy = $item[9];
	$isell = $item[10];
	$ilevel = $item[11];
	$istone = $item[12];
	$ishowlvl = $item[13];
	$ikind = $item[14];
	$iimg = $item[15];
	$idescription = $item[16];

	echo '
	<td class="tdn" valign="center" width="300"><img src="img/i/1_'.$iimg.'.jpg" alt="'.$iname.'" ></td>
	<td class="tdn" valign="top" width="700">
	<b>'.$iname.'</b><br>(Your inventory: 0 item(s))';
	if ($istrenght > 0) {
	echo '<br>Force +',$istrenght;
	} elseif ($istrenght == 0) {
	} elseif ($istrenght < 0) {
	echo '<br>Strenght ',$istrenght;
	}
	if ($idefence > 0) {
	echo '<br>Defence +',$idefence;
	} elseif ($idefence == 0) {
	} elseif ($idefence < 0) {
	echo '<br>Defence ',$idefence;
	}
	if ($iagility > 0) {
	echo '<br>Dexterity +',$iagility;
	} elseif ($iagility == 0) {
	} elseif ($iagility < 0) {
	echo '<br>Dexterity ',$iagility;
	}
	if ($iendurance > 0) {
	echo '<br>Endurance +',$iendurance;
	} elseif ($iendurance == 0) {
	} elseif ($iendurance < 0) {
	echo '<br>Endurance ',$iendurance;
	}
	if ($icharisma > 0) {
	echo '<br>Charisma +',$icharisma;
	} elseif ($icharisma == 0) {
	} elseif ($icharisma < 0) {
	echo '<br>Charisma ',$icharisma;
	}
	echo '<br>';
	echo '<br>Price: ',number_format($ibuy,0,",","."),' <img src="img/res2.gif" alt="gold" align="absmiddle" border="0">';
	if ($istone > 0) {
	echo ' + ';
	echo $istone;
	echo ' <img src="img/res3.gif" alt="gold" align="absmiddle" border="0">';
	}
	echo '<br>Resale value: ',number_format($isell,0,",","."),' <img src="img/res2.gif" alt="Gold" align="absmiddle" border="0"><br>Requirements: character level  ',$ilevel,'</td>
	<td class="tdn" valign="center" align="center" width="200">';
	if ($user->Gold >= $ibuy) {
	if ($user->Stones >= $istone) {
	if ($user->Level >= $ilevel) {
	echo '<a href="shop.php?typ=1&c=1&b=',$iid,'" target="_top" class="headlines">buy</a>';
	} elseif ($user->Level < $ilevel) {
	echo '---';
	}
	} else {
	echo '---';
	}
	} else {
	echo '---';
	} 
	echo '</td></tr>
	';

	} 


}

that is the whole function.

 

function qstr ( $string, $magic_quotes = false )
	{
		if (!$magic_quotes) {
			if (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
				return "'" . mysql_real_escape_string($string) . "'";
			}
			$string = str_replace("'", "\\'" , str_replace('\\', '\\\\', str_replace("\0", "\\\0", $string)));
			return  "'" . $string . "'"; 
		}
		return "'" . str_replace('\\"', '"', $string) . "'";
	}

maybe its from str_replace,but i dont think it should be a problem

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.