Acmlm's Board - I2 Archive - Programming - Showing all rows [PHP] [MySQL]
User | Post |
Darth Coby
Posts: 218/1371 |
Well, since $row[$i] was empty I decided to use $next like acmlm told me, it works now. Thanks. |
Acmlm
Posts: 377/1173 |
Hmm, 2 things here ...
First, $row[$i] in the while loop is empty (else you'd get "array[date]" and so on), try using $next instead or changing the loop ...
And secondly (although that wouldn't matter anymore if you use $next), multidimensional arrays can't be included directly in quotes for printing/etc., so you have to do it like this:
print "Date: ".$row[$i][date]."<br>";
Tuvai
Posts: 114/211 |
Instead of print "Date: $row[$i][date] ";
Try print "Date:".$row[$i][date]; |
Darth Coby
Posts: 217/1371 |
$sql = mysql_query("SELECT * FROM kt15x_main"); for($i=0;$row[$i]=mysql_fetch_array($sql, MYSQL_BOTH);$i++); while($next = next($row)){ print "Date: $row[$i][date] "; print "IP: $row[$i][ip] "; print "Visitor number: $row[$i][counter] "; print "Browser: $row[$i][browser] "; print "Came from: $row[$i][referer]
"; }
That doesn't work, it just prints "Date: [date]". What did I do wrong?
|
Acmlm
Posts: 365/1173 |
Of course it can be done
$somearray[test]="hello"; $biggerarray[w00t]=$somearray; print $biggerarray[w00t][test]; //prints "hello"
Or more specifically:
$res=mysql_query("SELECT * FROM something"); for($i=0;$row[$i]=mysql_fetch_array($res);$i++);
Then $row becomes an array containing all the rows, and $i stops at the number of rows ... and then you can do stuff like this:
print $row[15][test]; //value of "test" field from row 15 (first row would be 0) |
Darth Coby
Posts: 183/1371 |
Is it possible to make an array with lots of arrays inside? I'd need it so I can load all the rows from my table and then print out the values from the rows. |
|
|