Page 1 of 1

href link cell contents

Posted: Tue Nov 03, 2009 12:21 pm
by dreeves
my php script outputs a table of invoices. I would like the user to be able to click on the invoice number and the entire invoice would appear.

Code: Select all

<table>
<tr>
<th><font face="Arial, Helvetica, sans-serif">Amount</font></th>
<th><font face="Arial, Helvetica, sans-serif">Activity</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Invoice Number</font></th>
</TR>
 
<?php
$i=0;
while ($i < $num) {
$amount=mysql_result($result,$i,"amount");
$activity=mysql_result($result,$i,"activity");
$name=mysql_result($result,$i,"name");
$invoice_number=mysql_result($result,$i,"invoice_number");
</TR>
 ?>
 
<tr>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $amount; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $activity; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $name; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $invoice_number; ?></font></td> 
// the $invoice_number would be a link to ../invoice_output.php?invoice_number=// whatever number is assigned to that row
</tr>
</TABLE>
<?php
$i++;
}
Thanks for the help.

Re: href link cell contents

Posted: Tue Nov 03, 2009 2:27 pm
by socalocmatt
I just want to clarify that this is what you want done. You have a list of invoices that look something like this:

1. Amount | Activity | Name | Invoice Number
2. Amount | Activity | Name | Invoice Number
3. Amount | Activity | Name | Invoice Number

When someone clicks on, let's say the invoice number on the second line, you want that invoices details to be shown like this:

1. Amount | Activity | Name | Invoice Number
2. Amount | Activity | Name | Invoice Number
Details of your invoice
appear here without the page reloading.
3. Amount | Activity | Name | Invoice Number

If this is the case then I think you will need to use javascript (AJAX) to grab the invoice's information and insert it into the page (DOM). Please advise if this is what you are trying to do.

Re: href link cell contents

Posted: Tue Nov 03, 2009 2:45 pm
by dreeves
It doesn't need to be that fancy. As the page exist, dozens of invoices are listed and at the top the user can enter the invoice number they would like to view in detail and hit submit. If they enter 104, then they will be sent to http://localhost/invoice_output.php?invoice_number=104

I would like them to be able to click on "104" in the record and be sent to the same page as mentioned above.

I hope that clarifies the situation and keeps me from having to use java.

Re: href link cell contents

Posted: Wed Nov 04, 2009 2:51 am
by socalocmatt
This might work for you:

Change

Code: Select all

 
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $invoice_number; ?></font></td>
 
to be

Code: Select all

 
<td align="center"><font face="Arial, Helvetica, sans-serif"><a href="http://localhost/invoice_output.php?invoice_number=<?php echo $invoice_number; ?>"><?php echo $invoice_number; ?></a></font></td>
 
Just be sure that invoice_output.php is using $_GET to retrieve invoice_number. If invoice_output.php is using $_POST then do this:

Code: Select all

 
<td align="center"><font face="Arial, Helvetica, sans-serif">
<form method="post" name="hiddenForm<?php echo $i; ?>">
   <input type="hidden" name="invoice_number" value="<?php echo $invoice_number; ?>">
</form>
<a href="javascript;" onClick="document.hiddenForm<?php echo $i; ?>.submit();return false">
<?php echo $invoice_number; ?></a></font></td>
 
It is rounding 1am here so you might want to double check this. :-)

Re: href link cell contents

Posted: Wed Nov 04, 2009 8:23 am
by dreeves
I used the first method (GET) and it worked great. Thanks a lot. That is going to be so useful.