• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Handling query results

fender

Limp Gawd
Joined
Mar 2, 2003
Messages
417
Let's say I have somethink like so:

Code:
		while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

			echo $row[0];
			echo '<br />';
			
		}

If there are 4 rows returned, whatever is being returned gets displayed four times. If numbers are being return, how would I obtain the following?

1
2
text
3
4
 
Do you mean how do you put text halfway through your returns?

Specify a bit more what you want, please. If you're trying to print half the rows, input your text, then print the second half, using two loops would be easiest.
 
If you want the text after 2 rows are returned it would be something like this:
Code:
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  if ($i == 2) {
    echo 'Whatever text you have to echo.';
  }
  echo $row[0] . '<br />' . "\n";
  $i = $i++;
}

If, on the other hand, you wanted the text half way between as many results as you have, you might try something like this:
Code:
$total = mysql_num_rows($result);
$half = ceil($total / 2);
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  if($i == $half) {
    echo 'Whatever text you have to echo.';
  }
  echo $row[0] . '<br />' . "\n";
  $i = $i++;
}

I think that should work. Try it out and let me know.
 
Back
Top