Jump to content

Alternating rows in while loop HELP


mbradley

Recommended Posts

Now i am not sure Y the heck this is happening and i thought it was simple but i have been working at it for 2 long think i need some new eyes looking at it:(  Can someone assit me? please:( 

 

I have table with 5 rows...

 

1

2

3

4

5

 

and it only prints

1,3,5

 

I don't see anything that would do that in my script but i prolly am missing it... please help me:(

 

<?php
define('_VALID_INCLUDE', TRUE);
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
$user = $_SESSION['myusername'];
$rank = $_SESSION['rank'];
$access = $_SESSION['cds'];
if($access == 0)
{
echo 'Sorry you don\'t have the right to access this page.<br>';
echo '<a href="../">Back to main page</a><br>';
echo '<a href="logout">LOGOUT</a><br>';
}else{
include 'lib/config.php';
include 'lib/opendb.php';
if($rank == 1){
$ranktitle = 'ADMIN';
$sqlowner = "SELECT DISTINCT name FROM CD";
$result_buyers = mysql_query($sqlowner) or die(mysql_error());
$sql = "SELECT * FROM `CD`"; 
}
else 
{
$ranktitle = 'Buyer';
$sql = "SELECT * FROM `CD` WHERE name = '$user'";
}
$result = mysql_query($sql) or die(mysql_error());
echo '<center>';
echo '<a href="logout">LOGOUT</a><br>';
echo '  --=-- ';
echo "Login Status: ",$ranktitle;
echo ' --=-- ';
if($rank == 1){
echo 'Total Buyers: ', mysql_num_rows($result_buyers);
echo ' --=-- ';
echo 'Total Purchases: ', mysql_num_rows($result);
echo ' --=-- ';
}
else{
echo 'Total Downloads: ', mysql_num_rows($result);
echo ' --=-- ';
}


	echo "<table border='1'>";
	echo "<tr><th>Track</th><th>download</th>";
	echo "<th>BUYER</th><th>purchased</th>"; 
	echo "</tr>";
if($rank == 1){$sql = "SELECT * FROM `CD`";}else{$sql = "SELECT * FROM `CD` WHERE name = '$user'";}
// keeps getting the next row until there are no more to get
$result1 = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
// Print out the contents of each row into a table
echo "<tr><td><center>"; 
echo $row[track];
echo "</center></td><td><center>";
?>
<a href="download.php?f=<?php echo $row[fname];?>'>
<?php
echo $row[fname];
echo "</a></center>";
echo "</td><td><center>";
echo $row[name];
echo "</center></td><td><center>";
echo $row[rltime];
echo "</center></td></tr>";

} 
?>
</table><center><br><br>
Created for us with Second Life<br>Saladin NightFire<br>Wolf Creations
</center>

<?php		
include 'lib/closedb.php';}

?>

Link to comment
https://forums.phpfreaks.com/topic/113262-alternating-rows-in-while-loop-help/
Share on other sites

Sorry to reply to myself but i thought this might help out others as well... the reason or well how i fixed it was i had bad .. well i put in the html link out of php and then went back to php... and that was BAD:)  LOL for the while loop... so i added it in the loop as a echo and worked fine now and all the rows are displayed:)

 

[move]FROM:[/move]

echo "</center></td><td><center>";
?>
<a href="download.php?f=<?php echo $row[fname];?>'>
<?php
echo $row[fname];
echo "</a></center>";

[move]TOO:[/move]

echo '</center></td><td><center>';
echo '<a href="download.php?f=';
echo $row[fname];
echo '">';
echo $row[fname];
echo '</a></center>';

 

I hope that helps someone else...:)

bc of the use of ( " ) in the html i used ( ' ) for the echo;)

You should have look into the concatenation operator to join strings. I'd change:

echo '</center></td><td><center>';
echo '<a href="download.php?f=';
echo $row[fname];
echo '">';
echo $row[fname];
echo '</a></center>';

to

echo '</center></td><td><center><a href="download.php?f=' . $row['fname']} . '">' . $row['fname'] . '</a></center>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.