Jump to content

Recommended Posts

I need help in makeing a table with the data that I have in my sql database. 

Here is a example of what is in my database.

ID Switch Start_Date Year Month Day Completed_by Comments

1  Test1  090309      2009 03      10    test                test

2  Test4  090309      2009 03      10    test                test2

3  Test2  090309      2009 03      10    test1              test3

in my sql query i am select * from table where year = year and completed_by =  completed_by

What i get know is this

Completed_By#SwitchesSwitches

test0Test4

test10Test2

What I want is this

Completed_By#SwitchesSwitches

test2Test4,Test1

test11Test2

Below is the Php code that I am useing

<?php do { ?>
<?php $myhash[$row_getPerson['Completed_By']] = $row_getPerson['Switch']; ?>
<?php } while ($row_getPerson = mysql_fetch_assoc($getPerson)); ?>
<?php
	$count = 0;
	arsort ($myhash);
	foreach ($myhash as $key => $value)
	{ $count++; 

	?>
<tr>
         <td nowrap="nowrap"><?php echo $key; ?></td>
         <td nowrap="nowrap"><?php echo $count;?></td>
         
      <td nowrap="nowrap"><?php echo $value; ?></td>
       </tr>
       <?php } ?>

Any Help would

 

 

Link to comment
https://forums.phpfreaks.com/topic/152242-solved-need-help-in-printing-array/
Share on other sites

<?php do {
$myhash[$row_getPerson['Completed_By']][] = $row_getPerson['Switch'];
} while ($row_getPerson = mysql_fetch_assoc($getPerson));
arsort ($myhash);
foreach ($myhash as $key => $value){
$count = count($value);
$value = implode(', ', $value);
echo "
<tr>
        <td nowrap=\"nowrap\">$key</td>
        <td nowrap=\"nowrap\">$count</td>
        <td nowrap=\"nowrap\">$value;</td>
   </tr>";
}

I made the changes.  Here is what I did

<?php do { ?>
<?php $myhash[$row_getPerson['Completed_By']][] = $row_getPerson['Switch']; ?>
<?php } while ($row_getPerson = mysql_fetch_assoc($getPerson)); ?>
       <?php
	arsort ($myhash);
	foreach ($myhash as $key => $value)
	{ 
		$count = count($value);
		$value = implode(', ', $value);
		echo "
		<tr>
         	<td nowrap=\"nowrap\"><$key</td>
         	<td nowrap=\"nowrap\"><$count</td>
            <td nowrap=\"nowrap\"><$value</td>
       </tr>";?>
       <?php } ?>

 

but it doesnt work.  This is what I get

Completed_By #Switches Switches

  <2

  <1

 

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.