Unstoppable Domains

PHP/SQL - While.. Help Please.

Spaceship Spaceship
Watch

LogiK

Established Member
Impact
11
Ok, I Am Building My Own Arcade Script.
(Not To Resell Just For My Own Use)

I Know How To Echo Out Game ect.
PHP:
$query=mysql_query("SELECT * FROM games ORDER by id DESC");
<? while($att = mysql_fetch_object($query)){ ?>
Then My HTML Here
<? } ?>

And That Would Echo Out Like:
Game1
Game2
Game3
Game4

But What I Want To Know How To Do Is Change It So That It Echos It Out Differently Like:
Game1 - Game2
Game3 - Game4

So It Has 2 Games Per Line.

Anyone Help?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Simple once someone shows you :P

If you just want a dash as your post indicates:
PHP:
<?php

$i = 0;

while( condition )
{
	echo ($i & 1) ? '-' : null;

	// Your bulky html here
	
	echo ($i & 1) ? '<br />' : null;
	$i++;
}
?>

If you want a table then the theory is the same but just with TR and TD.
 
Last edited:
1
•••
PHP:
<?php
$query=mysql_query("SELECT * FROM games ORDER by id DESC"); 
$c = 0;
while($att = mysql_fetch_assoc($query)){ 
if($c == 0) { echo $att['gamename']." - "; $c++;  }
else { echo $att['gamename']."<br />"; $c = 0; }
} 
?>
 
0
•••
bliss, since we are now handing people things on plates :)

PHP:
<?php
$query = mysql_query("SELECT * FROM games ORDER by id DESC"); 
$c = 0;

while( $att = mysql_fetch_assoc( $query ) ) 
{ 

	echo ($c & 1) ? " - {$att['gamename']}<br />" : $att['gamename'];
	
	/*
		if($i & 1) 
		{
			echo "- {$att['gamename']}<br />";
		}
		else
		{
			echo $att['gamename'];
		} 
	*/
	$c++;
} 
?>

A little cleaner than the 2 conditionals :)
 
Last edited:
0
•••
What exactly does the & do in if ($i & 1)?
I normally do if ($i % 2) or something.
 
0
•••
Dan said:
What exactly does the & do in if ($i & 1)?
I normally do if ($i % 2) or something.

Ahhh, will never get any revision done :hehe:
Using PHP's bitwise And operator (&), we can check to see if the 1-bit is on or off. If it's on, we have an odd number, otherwise, an even number.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back