vote-for-pedro Posted July 12, 2007 Share Posted July 12, 2007 Hi, im using the following code to output everything in a database table under headings in an html table untill theres no more data left. The headings are things like name address etc. could i make it so when all the data is shown each name or ID becomes a link and when clicked takes the user to a more detailed page on the selected client. because of the way the table is generated there is no where to place link tags. is there a more appropriate way that is more editable? it would be nice to have checkboxes at the edge of each customer also to enable a complete status or deleting a client from the table. // Show the customer in an HTML <table> function displayStock($result) { // Start a table, with column headers echo "\n<table border=\"0\">\n<tr bgcolor=\"lightblue\">\n" . "\n\t<th>ID</th >" . "\n\t<th>Name</th>" . "\n\t<th>Address</th>" . "\n\t<th>Address2</th>" . "\n\t<th>Address3</th>" . "\n\t<th>Address4</th>" . "\n\t<th>Post code</th>" . "\n\t<th>Tell Number</th>" . "\n\t<th>Fax Number</th>" . "\n\t<th>Emaill Address</th>" . "\n\t<th>Voucher Code</th>" . "\n\t<th>Fitting Method</th>" . "\n\t<th>Fitting Address</th>" . "\n\t<th>Ideal fitting Date</th>" . "\n\t<th>Vehicle Model</th>" . "\n\t<th>Vehicle Reg</th>" . "\n\t<th>Notes</th>" . "\n\t<th>Date form submitted</th>" . "\n</tr >"; // Until there are no rows in the result set, // fetch a row into the $row array and ... while ($row = @ mysql_fetch_row($result)) { // ... start a TABLE row ... echo "\n<tr >"; // ... and print out each of the attributes // in that row as a separate TD (Table Data). foreach($row as $data) echo "\n\t<td bgcolor=\"silver\" > $data </td>"; // Finish the row echo "\n</tr>"; } // Then, finish the table echo "\n</table >\n"; } if (!($result = @ mysql_query ("SELECT * FROM mirrorcam ORDER BY id desc", $connection ))) showerror( ); // Display the results displayStock($result); // Close the connection if (!(mysql_close($connection))) showerror( ); ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 12, 2007 Share Posted July 12, 2007 Yes why not: Try it like this. while ($row = @ mysql_fetch_row($result)) { // ... start a TABLE row ... echo "<a href='user_details.php?id=$row->id'>$row->name</a>"; This is just an example how to do it, change it to ur script and db tables. Quote Link to comment Share on other sites More sharing options...
vote-for-pedro Posted July 12, 2007 Author Share Posted July 12, 2007 thanks mmarif4u think thats on the right line but it dosent seem to work (no link at all) ive noticed you can remove the // ... start a TABLE row ... echo "\n<tr >"; completely and its still works the same. can you explain your code a little more thanks Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 12, 2007 Share Posted July 12, 2007 echo "<a href='user_details.php?id=$row->id'>$row->name</a>"; I put this line in ur while statement. U can modify it ur query. Here id is the table primary field for every user, when u click it , it will go to next page, which u have to make like user_details.php. Now it depends on your code how u make it for user. Quote Link to comment Share on other sites More sharing options...
vote-for-pedro Posted July 12, 2007 Author Share Posted July 12, 2007 ok if i change echo "<a href='voucherview.php?id=$row->id'>$row->name</a>"; to echo "<a href='voucherview.php?id=$row->id'>anythingelse</a>"; it shows a list of links above the table (same amount of links as database entries) with the code as you had it no links appear in the id field. do i need to incorporate the echo "\n<tr >"; as well, but as mentioned if i remove the entire ... start a TABLE row ... section the table is still created succesfully. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 12, 2007 Share Posted July 12, 2007 it depends on ur html table, how u create it where u want to put this line in ur html table coding to view it properly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.