I have a cycle:

for ($i = 1; $i <= $sql2['count']; $i++) { $result = mysql_query("SELECT * FROM inv where username='".$_SESSION['username']."' "); while ($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); "; } } 

Is it possible to do that?

And there is also an error; new Array prints to duplicate like this:

 i[1] i[1] i[2] i[2] 

Please tell me how to fix it.

  • 3
    You are already asking the same question for the third or fourth time. - Shamanis
  • -_- answer is generally cool - oOKomarOo

2 answers 2

oh mother my woman ...

 $result = mysql_query("SELECT * FROM inv where username='".mysql_real_escape_string($_SESSION['username'])."'"); $i = 1; while ($inv= mysql_fetch_array($result)){ echo "\ni[$i] = new " . "Array('".$inv['id']."','".$inv['id_img']."','". $inv['kolovo']."',0,'". $inv['title']."',0,'". $inv['about']."',0,1); "; $i++; } 
  • Yeee thanks =) - oOKomarOo

I hope I truly understood that the output in JS ...

IMHO:

 $username = mysql_real_escape_string( $_SESSION['username'] ); $query = mysql_query( "SELECT * FROM inv where username = '".$username."'" ); echo 'i = [ undefined ];'."\n"; while ( $row = mysql_fetch_array( $query ) ){ echo ''. 'i.push(['. ' "'.$row['id']. '",'. ' "'.$row['id_img'].'",'. ' "'.$row['kolovo'].'", 0,'. ' "'.$row['title']. '", 0,'. ' "'.$row['about']. '", 0, 1'. ']);'."\n"; } 

PS:

  1. You support the code, so long single-line expressions are not very good!
  2. It is better not to call the variable i - if it is not a loop counter
  3. IMHO: the result of mysql_query is $query, $sql, $query_inv , but not $inv