how to remake this code:
for ($i = 1; $i <= $sql2['count']; $i++) { $result = mysql_query("SELECT * FROM inv where username='".$_SESSION['username']."'"); $inv = mysql_fetch_array($result); echo " i[$i] = new Array('".$inv['id']."','".$inv['id_img']."','".$inv['kolovo']."',0,'".$inv['title']."',0,'".$inv['about']."',0,1); "; }
That ALL values, and not just one were deduced?
Here is the whole code:
<?php session_start(); mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db(pokefriends) or die(mysql_error()); $sql = mysql_query("SELECT * FROM users where id='".$_SESSION['id']."'"); $row = mysql_fetch_array($sql); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Инвентарь</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; Charset=Windows-1251"> <STYLE> body { background: #2685c9; COLOR: #fedab3; FONT-SIZE: 13px; FONT-FAMILY: Tahoma; } #divTip { position:absolute; padding:1 2 1 2; background-color: #2685c9; border: solid 1px 2685c9; text-align:justify; COLOR: #fedab3; FONT-SIZE: 11px; FONT-FAMILY: Tahoma; z-index:10; visibility:hidden; } </STYLE> <script> function defPosition(event) { // координаты мыши var x = y = 0; if (document.attachEvent != null) { x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); } else if (!document.attachEvent && document.addEventListener) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } else { // Do nothing } return {x:x, y:y}; } page=0; invType=0; function tip(event, ID) { if (event) { document.getElementById('divTip').style.left=defPosition(event).x+15; document.getElementById('divTip').style.top=defPosition(event).y+10; document.getElementById('divTip').innerHTML=i[ID][15]; document.getElementById('divTip').style.visibility='visible'; } else document.getElementById('divTip').style.visibility='hidden'; } function pic(ID,sitID,am,uw,dr) { for (s=0;s<document.images.length;s++) document.images[s].style.border='1px solid #aecff1'; document.getElementById("pic"+ID).style.border='1px solid black'; document.getElementById('formit')['itID'].value=sitID; document.getElementById('formit')['amount'].value=am; document.getElementById('formit')['but1'].style.display=(uw?'inline':'none'); document.getElementById('formit')['but2'].style.display=(dr?'inline':'none'); document.getElementById('formit')['pokes'].style.display=(uw||dr?'block':'none'); eval("CURpic.src=pic"+ID+".src"); CURname.innerHTML=document.getElementById('divTip').innerHTML; } function formatnum(str) { str = str + ''; var retstr = ''; var now = 0; for (j = str.length-1; j>=0; j--) { if (now < 3) { now++; retstr = str.charAt(j) + retstr; } else { now = 1; retstr = str.charAt(j) + '.' + retstr; } } return retstr; } function use_item(add) { document.getElementById('add').value=add; document.getElementById('formit').submit(); } <?php $sql = mysql_query("SELECT COUNT(*) as count FROM inv WHERE username='".$_SESSION['username']."'"); $sql2 = @mysql_fetch_array($sql); ?> itemsamount = <?php echo $sql2['count']; ?> ;i = new Array( <?php echo $sql2['count']; ?>); i[0] = new Array(<?php echo $_SESSION['id']; ?>,1,<?php echo $row['money']; ?>,0,'Кредит',0,'Вес: 0<br>',0,6); <?php for ($i = 1; $i <= $sql2['count']; $i++) { $result = mysql_query("SELECT * FROM inv where username='".$_SESSION['username']."'"); $inv = mysql_fetch_array($result); echo " i[$i] = new Array('".$inv['id']."','".$inv['id_img']."','".$inv['kolovo']."',0,'".$inv['title']."',0,'".$inv['about']."',0,1); "; } ?> function fillupinv() { p=page*40; content=""; prints=1; while (prints<=40 && i[p]) { if (invType==0 || i[p][8]==invType) { picF=i[p][1]+'.gif'; if (i[p][1]>=74 && i[p][1]<=123) picF='TM'+'.gif'; if (i[p][1]>=123 && i[p][1]<=130) picF='HM'+'.gif'; if (i[p][1]==250) picF='cards/'+i[p][7]+'.gif'; if (i[p][1]==144) picF = i[p][7] ? 'eggs/'+i[p][7]+'.png' : '144.gif'; i[p][15]= i[p][4] + ' <b><small>x</small>'+formatnum(i[p][2])+'</b>'; if (i[p][6]) i[p][15]+='<br><span class=itemdescr>'+i[p][6]+'</span>'; content+="<div class=item><img class='item' ID=\"pic"+p+"\" src=\"/img/item/"+picF+"\" onClick=\"pic("+p+","+i[p][0]+","+i[p][2]+","+i[p][3]+","+i[p][5]+")\" onMouseMove=\"tip(event,"+p+");\" onMouseOut=\"tip(0); \"></div>"; prints++; } p++; } for (k=prints; k<=40; k++) content+="<div class=item><img src='/img/item/blank.gif'></div>"; document.getElementById('inv').innerHTML=content; if (page>0) {document.getElementById('divprev').innerHTML="<a href='javascript:' onclick='page--;fillupinv();'><<</a>";} else {document.getElementById('divprev').innerHTML="<span style='color:#92b1dd'><<</span>";} if (itemsamount>p) {document.getElementById('divnext').innerHTML="<a href='javascript:' onclick='page++;fillupinv();'>>></a>";} else {document.getElementById('divnext').innerHTML="<span style='color:#92b1dd'>>></span>";} } </script> <STYLE> IMG {width:32; height:32; visibility:visible; border:1px solid #aecff1; margin:3px} IMG.item{CURSOR:POINTER;} BODY {margin:5 5 5 5;} div.item { background-color:#4c91f9; margin:1px; float:left; width: 40px; height: 40px; } </STYLE> </HEAD> <BODY onload="fillupinv()" style="width:600; height:350;"> <H1>Инвентарь</H1> <div id="divTip"></div> <TABLE align="left" width="600"><TR><TD width="345" valign=top> <DIV ID="inv"> </DIV> <br><TABLE width="335" style="font-weight:bold; font-size:12px;"> <TD align=left><DIV id="divprev"> </DIV></TD><TD align=center> <small><a href="javascript:history.go(0)">- обновить -</a></small> </TD><TD align=right><DIV id="divnext"> </DIV></TD> </TABLE> </TD><TD valign=top> <DIV id="CURname"> </DIV> <br> <img ID="CURpic" src="/img/item/blank.gif" width="32" height="32" border="0" style="CURSOR:DEFAULT"><br> <form action="game.php?fun=use_item&map=1" method="post" id="formit"> <input name="amount" type="text" value="" SIZE=10><BR> <input name="but0" type="button" value="Выкинуть" onclick="if (confirm('Вы уверены что хотите выбросить предмет?')) use_item('drop');"><P> <P> <select size="1" name="pokes" style='display:none'><P> <input name="but1" style='display:none' type="button" value="Использовать" onclick="use_item('use');"> <input name="but2" style='display:none' type="button" value="Одеть" onclick="use_item('dress');"> <input name="itID" type="hidden" value=""> <input name="add" id="add" type="hidden" value=""> </form> </TD></TR><TR><TD> </TD></TR></TABLE> </body> </html>