Jump to content
The Uniform Server Community

Recommended Posts

Posted

In my script, all the records in the database are output into a table. One of the columns is the primary key (Invoice Number). I would like for each Invoice Number to be a link, so when selected the user will be directed to a page where they can see and edit the entire record (invoice). How would I do that? I already have a page written that will display the information, I just don't have a way of telling it which record to display.

Here is the code:

 

<?

include("dbinfo.inc.php");

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

?>

<table border="0" cellspacing="2" cellpadding="2">

<tr>

<th><font face="Arial, Helvetica, sans-serif">Invoice Number</font></th>

<th><font face="Arial, Helvetica, sans-serif">Name</font></th>

<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>

<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>

<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>

<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>

<th><font face="Arial, Helvetica, sans-serif">Website</font></th>

</tr>

 

<?

$i=0;

while ($i < $num) {

$Invoice_Number=mysql_result($result,$i,"Invoice_Number");

$first=mysql_result($result,$i,"first");

$last=mysql_result($result,$i,"last");

$phone=mysql_result($result,$i,"phone");

$mobile=mysql_result($result,$i,"mobile");

$fax=mysql_result($result,$i,"fax");

$email=mysql_result($result,$i,"email");

$web=mysql_result($result,$i,"web");

?>

 

<tr>

<td><font face="Arial, Helvetica, sans-serif"><? echo "$Invoice_Number"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>">E-mail</a></font></td>

<td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td>

</tr>

<?

++$i;

}

echo "</table>";

 

 

?>

Posted

Hello,

Sorry this is delayed.

 

Note: I changed your code a bit to make it better. Have added a edit link, which goes to editinvoice.php passing its invoice number. You just need to GET the id on this file and you can use it for your query.

 

 
<?
include("dbinfo.inc.php");
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

echo "<b><center>Database Output</center></b><br><br>";
?>

<table border="0" cellspacing="2" cellpadding="2">
 <tr>
<th><font face="Arial, Helvetica, sans-serif">Invoice Number</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>
<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">Website</font></th>
<th> </th>
 </tr>
 
 <?
	$query="SELECT * FROM contacts";
	$result=mysql_query($query);
	
	while ( $rows = mysql_fetch_assoc($result) ) {
 ?>
 
 <tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $rows['Invoice_Number'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $rows['first'];?> <?=$rows['last'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $rows['phone'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $rows['mobile'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $rows['fax'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo $rows['email'];?>">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="<? echo $rows['web'];?>">Website</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="editinvoice.php?id=<? echo $rows['Invoice_Number'];?>">Edit Invoice</a></font></td>
 </tr>
<?
	}
?>
</table>

ATOMIC Web Hosting 2007 - 2011

Shared Hosting - Reseller Hosting - Dedicated Servers - Virtual Private Servers (Request Dedicated/VPS Servers via E-mail)

E-mail: sales@atomicwebhosting.com Website: http://www.atomicwebhosting.com/

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...