Hi guys!
I want to do something like this:
$count=0;
while ($count < $something) { print "$array[$count]";
count++;
}
Of course this doesnt work. Any ideas why? Its something in how im trying to display that array $array[$count] .
Thank you!
It should work, provided your array is numerically indexed. It's a common way to do it.
Array Functions
I thought it should work to but i get nuthin. No error, no output. 🙁
Im using this to populate the array .. which should by default should be indexed I think??
mysql_fetch_array($result)
Post your actual code (the relevant parts).
<? while($res = mysql_fetch_array($result)):?> <tr> <? for ($i = 0; $i < mysql_num_fields( $result ); ++$i): ?> <? $count++; ?> <td><?=$result[$count]?></td>
<? endfor; ?><? $count = 0; ?>
</tr> <? endwhile;?>
Man.. thats neer impossible to read. Why are you going in and out of php like that?
Anyway.. try this.
<?php while($res = mysql_fetch_array($result)) { echo "<tr>"; for ($i = 0; $i < mysql_num_fields( $result ); ++$i) { echo "<td>{$res[$i]}</td>"; } $i = 0; echo "</tr>"; } ?>
Think I figured it out, I want to fetch with mysql_fetch_array($result, MYSQL_BOTH)
Oh, Ok thorpe, yah that makes more sense. Thank you!
Not at all. MYSQL_BOTH is default.
Your code is a bit all over the place. You increment a $count variable that is never instatiated. Your also trying to display an index of $result which is NOT an array. $res is the array.