php and mysql record selection trouble
Posted: Wed Jul 09, 2003 12:19 am
I am having some trouble here with my code it seems. Here is what I am wanting to achieve. I have setup a table that creates invoices through a PHP webpage (to make it easy on the end user). Now, I also have a view link that allows the end user to see all the invoices that have been created - with only a few fields showing, plus a view link that should take the current record that the current view link is attached to and extract all columns from one record result and output it to a new page.
Here is the "queried" table code (the short table view of all records)...
/* go here (http://www.texascarts.com/invoices/view_all.php) to see the follow code in action */
And here is the code for "cur_invoice.php" - the href of the View link...
I know my problem is with that view link that I have attached to each record.
If you'll notice when looking at the "view_all.php" page, I created a query that only shows 3 columns of each record (and these are fake records btw, I'm just using these for practice). Now, what I want this to do, is when I click on the view link associated with each record, it should open up a new page with all the columns of that one record - basically displaying the enire invoice.
I know my problem lies with the view link, I just don't know what to do.
Here is the "queried" table code (the short table view of all records)...
/* go here (http://www.texascarts.com/invoices/view_all.php) to see the follow code in action */
Code: Select all
<?php
include('dbinfo.inc.php');
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM invoices ORDER BY inv_date, inv_id ASC";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();
echo "<b><center>View All Invoices</center></b><br><br>";
?>
<table border="0" cellspacing="8" cellpadding="8">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Date</font></th>
<th><font face="Arial, Helvetica, sans-serif">Invoice #</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$inv_date = mysql_result($result,$i,"inv_date");
$inv_id = mysql_result($result,$i,"inv_id");
$inv_cstname = mysql_result($result,$i,"inv_cstname");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$inv_date"; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><? echo "$inv_id"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$inv_cstname"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="cur_invoice.php">View</a></font></td>
</tr>
<?
++$i;
}
echo "</table>";
?>Code: Select all
<?php
include('dbinfo.inc.php');
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM invoices";
$result = mysql_query($query);
mysql_num_rows($result);
mysql_close();
$inv_id = mysql_result($result,"inv_id");
$inv_date = mysql_result($result,"inv_date");
$inv_cstname = mysql_result($result,"inv_cstname");
echo "$inv_id<br>$inv_date<br>$inv_cstname";
?>If you'll notice when looking at the "view_all.php" page, I created a query that only shows 3 columns of each record (and these are fake records btw, I'm just using these for practice). Now, what I want this to do, is when I click on the view link associated with each record, it should open up a new page with all the columns of that one record - basically displaying the enire invoice.
I know my problem lies with the view link, I just don't know what to do.