Help with formatting results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Help with formatting results

Post by me! »

I am trying to get some results into a table and am not sure how to make it work as I would like.

The problem is that I changed the format for storing a users name in the db form “name” to “first_name” and “last_name” now my table has one more column than I want, I want first name and last name in the same cell... But am not sure the best way to do it?

What I have:
A table with all the results inserted in order and then two form option at the end of the row.

Code: Select all

// Format the results table
echo "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><h2>Members, $today</h2>";

// Set the headings
echo "<tr><td><h2>Member Name</h2></td><td><h2>Call Sign</h2></td><td><h2>Phone</h2></td><td><h2>Mem. Expites</h2></td><td><h2>Mem. ID</h2></td><td><h2>Options</h2></td></tr>";

// Poop out some date!
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
	$pn_uname = $line['pn_uname']; // need this for the form, in table.
	$name = $line['pn_first_name'] ['pn_last_name']; // also need this for the form, in table.
	   echo "<tr>";
   foreach ($line as $col_value) {
       echo "<td><div align=\"center\">$col_value</div></td>";
   }
   echo '<td><div align="center">
   			<table border="0" cellpadding="0" cellspacing="0" width="100%" id="table2">
				<tr>
        		<td class="memform"><div align="center">
				<form action="mem_search.php" method="post"><input type="hidden" name="call" value="' . $pn_uname .'" />
   				<input type="image" src="/images/edit_icon_16.gif" alt="Edit" title="Edit ' . $pn_uname .' Information" />
				</form></div>
				</td>
        		<td class="memform"><div align="center"><form action="mem_drop_user.php" method="post">
				<input type="hidden" name="call" value="' . $pn_uname .'" />
				<input type="hidden" name="name" value="' . $name .'" />
				<input type="image" src="/images/button_cancel_16.gif" alt="Delete" title="Delete This Member" />
				</form></div>
				</td>
      			</tr>
    		</table>	
			</div></td>';
   echo "</tr>";
}
echo "</table>";
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$name = $line['pn_first_name'] .' '. $line['pn_last_name'];
It's called the concatenation operator Image
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post by me! »

Thanks Jcart, I had not learned of that one yet.

I don't see how it helps me with the results in the table thow, I think maybe I need to change this?

Code: Select all

foreach ($line as $col_value) {
              echo "<td><div align=\"center\">$col_value</div></td>";

----------------------------------------------- full code -----------------------------------

Code: Select all

// Format the results table
echo "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><h2>Members, $today</h2>";

// Set the headings
echo "<tr><td><h2>Member Name</h2></td><td><h2>Call Sign</h2></td><td><h2>Phone</h2></td><td><h2>Mem. Expites</h2></td><td><h2>Mem. ID</h2></td><td><h2>Options</h2></td></tr>";

// Poop out some data!
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $pn_uname = $line['pn_uname']; // need this for the form, in table.
        $name = $line['pn_first_name'] .' '. $line['pn_last_name'];  // also need this for the form, in table.
   echo "<tr>";
            foreach ($line as $col_value) {
              echo "<td><div align=\"center\">$col_value</div></td>";
              }
   echo '<td><div align="center">
             <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table2">
                 <tr>
                    <td class="memform"><div align="center">
                         <form action="mem_search.php" method="post"><input type="hidden" name="call" value="' . $pn_uname .'" />
                         <input type="image" src="/images/edit_icon_16.gif" alt="Edit" title="Edit ' . $pn_uname .' Information" />
                         </form></div>
                     </td>
                     <td class="memform"><div align="center"><form action="mem_drop_user.php" method="post">
                          <input type="hidden" name="call" value="' . $pn_uname .'" />
                          <input type="hidden" name="name" value="' . $name .'" />
                          <input type="image" src="/images/button_cancel_16.gif" alt="Delete" title="Delete This Member" />
                          </form></div>
                     </td>
                  </tr>
            </table>   
            </div></td>';
   echo "</tr>";
}
echo "</table>";
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post by me! »

Ok I got it working but not with pn_first_name, and pn_last_name, but rather just one called pn_name that is a combination of first and last. I know it’s dumb to have a three in the db but the system needs the pn_name on already and now I need the first and last names for some new areas. If there a way to separate the first and last name from the name one?

Anyway I am still wondering about the formatting of the table, Should I just be looping the rows with specific variables in them or is the way it’s being done, the best?
Post Reply