Jump to content

[SOLVED] Data Loop


smti

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

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.