Jump to content

Recommended Posts

Hello,

 

I have a small problem; I have a table which displays records pulled from a database. This table has different colors (denoted by the class tag -- see code below). Anyway, I want to be able to pull the records from the database and alternate the table colors properly. At the moment, when I grab the data, it displays the records in alternating colors, but the data is the same. I'm not quite sure what the problem is. Here is my code: <b>(A screen shot is also available).</b>

 

echo "<tbody>
	<tr>
		<td>$row[mrn]</td>
		<td>$row[auditdate]</td>
		<td>$row[auditorid]</td>
		<td>$row[codername]</td>";

		//Grab ID and put in variable (REQUIRED!)
		$id=$row[id];


		echo "<td><img src='images/icons/view.png' alt='View Record'/> <img src='images/icons/pencil.png' /> <a href='../../../functions/delete.php?id=$id'><img src='images/icons/trash.png' /></a></td>
	</tr>
	<tr class='alt'>
		<td>$row[mrn]</td>
		<td>$row[auditdate]</td>
		<td>$row[auditorid]</td>
		<td>$row[codername]</td>
		<td><img src='images/icons/view.png' alt='View Record'/> <img src='images/icons/pencil.png' /> <a href='../../../		functions/delete.php?id=$id'><img src='images/icons/trash.png' /></a></td>
	</tr>";
	}
?> 

 

Please also see the attached image. Any help would be greatly appreciated!

 

Thanks,

 

smti

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/106011-solved-data-loop/
Share on other sites

Hello.

 

As you requested, the query looks like this:

 

  $result = mysql_query("SELECT * FROM cases_bloomsburg") 
     	or die(mysql_error());  

	// keeps getting the next row until there are no more to get
           while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table

Link to comment
https://forums.phpfreaks.com/topic/106011-solved-data-loop/#findComment-543346
Share on other sites

try

<?php

$result = mysql_query("SELECT * FROM cases_bloomsburg") 
     	or die(mysql_error());  

$count=0;
echo '<tbody>';	
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
$classStr = $count++ % 2 ? '' : "class='alt'";
echo "<tr $classStr>
		<td>{$row['mrn']}</td>
		<td>{$row['auditdate']}</td>
		<td>{$row['auditorid']}</td>
		<td>{$row['codername']}</td>";

		//Grab ID and put in variable (REQUIRED!)
		$id=$row['id'];


		echo "<td><img src='images/icons/view.png' alt='View Record'/> <img src='images/icons/pencil.png' /> <a href='../../../functions/delete.php?id=$id'><img src='images/icons/trash.png' /></a></td>
	</tr>";
}
echo '</tbody>';	

?>

Link to comment
https://forums.phpfreaks.com/topic/106011-solved-data-loop/#findComment-543419
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.