Jump to content

create a link in a table from echo 'ed sql data


vote-for-pedro

Recommended Posts

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(  );
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.