Jump to content

Need view/edit link on rows whilst paging.


giraffemedia

Recommended Posts

Hello

 

i'm trying to insert a view and edit link on each row of the results returned from my database query. I'm using paging to display all the results returned from the query, and this is working fine and dandy. The view_records.php  page consists of a query which returns the id (primary key), company name and section name to a list of 20 results per page.

 

The actual rows contain much more data than this but i'm using the view_records.php as a preview to be able to quickly scroll through the records and would like a user to be able to either view the row as a page in full, or edit the page in full (all the users are trusted 100% so security is not an issue).

 

How can I take the individual row id and open this to view the full info, and how can I do this to edit the information?

 

I have uploaded a screenshot of the results to get an idea at http://www.bluntcreative.co.uk/testing/php_paging.png

 

The code for my page is below:

 

 

 

</head>

<body>

 

<div id="wrapper">

 

<div id="main_nav">

 

<?PHP include ("./main_nav.php"); ?>

 

</div>

 

 

<div id="main_content">

 

<h1>Customer Management test</h1>

 

<?php

include './includes/config.php';

include './includes/opendb.php';

 

@$column_name=$_GET['column_name']; // Read the column name from query string.

 

 

$start=$_GET['start']; // To take care global variable if OFF

if(!($start > 0)) {                        // This variable is set to zero for the first page

$start = 0;

}

 

$eu = ($start - 0);

$limit = 20;                                // No of records to be shown per page.

$this1 = $eu + $limit;

$back = $eu - $limit;

$next = $eu + $limit;

 

 

/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////

$query2=" SELECT * FROM contacts  ";

$result2=mysql_query($query2);

echo mysql_error();

$nume=mysql_num_rows($result2);

/////// The variable nume above will store the total number of records in the table////

 

/////////// Now let us print the table headers ////////////////

$bgcolor="#f1f1f1";

echo "<TABLE id=results_table width=100% align=center  cellpadding=0 cellspacing=0> <tr>";

echo "<td  bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='4'><a href='$page_name?column_name=id'>Id</a></font></td>";

echo "<td  bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='4'><a href='$page_name?column_name=companyname'>Company Name</a></font></td>";

echo "<td  bgcolor='dfdfdf'> <font face='arial,verdana,helvetica' color='#000000' size='4'><a href='$page_name?column_name=section'>Section</a></font></td>";

echo "<td  bgcolor='dfdfdf'> <font face='arial,verdana,helvetica' color='#000000' size='4'>View</font></td>";

echo "<td  bgcolor='dfdfdf'> <font face='arial,verdana,helvetica' color='#000000' size='4'>Edit</font></td></tr>";

 

 

////////////// Now let us start executing the query with variables $eu and $limit  set at the top of the page///////////

$query=" SELECT * FROM contacts  ";

 

if(isset($column_name) and strlen($column_name)>0){

$query = $query . " order by $column_name";

}

$query = $query. " limit $eu, $limit ";

$result=mysql_query($query);

echo mysql_error();

 

//////////////// Now we will display the returned records in side the rows of the table/////////

while($noticia = mysql_fetch_array($result))

{

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}

else{$bgcolor='#f1f1f1';}

 

echo "<tr >";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[id]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[companyname]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[section]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><a href=view_record.php?id=$results[id]>View</a></font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><a href=edit_record.php?id=$results[id]>Edit</a></font></td>";

 

echo "</tr>";

}

echo "</table>";

////////////////////////////// End of displaying the table with records ////////////////////////

 

/////////////// Start the buttom links with Prev and next link with page numbers /////////////////

echo "<tr><table align = 'center' width='100%'><td  align='right' width='40%'>";

//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////

if($back >=0) {

print "<a href='$page_name?start=$back&column_name=$column_name'><font face='Verdana' size='2'>PREV</font></a>";

}

//////////////// Let us display the page links at  center. We will not display the current page as a link ///////////

echo "</td><td align=center width='20%'>";

$i=0;

$l=1;

for($i=0;$i < $nume;$i=$i+$limit){

if($i <> $eu){

echo " <a href='$page_name?start=$i&column_name=$column_name'><font face='Verdana' size='2'>$l</font></a> ";

}

else { echo "<font face='Verdana' size='4' color=red>$l</font>";}        /// Current page is not displayed as link and given font color red

$l=$l+1;

}

 

 

echo "</td><td  align='left' width='40%'>";

///////////// If we are not in the last page then Next link will be displayed. Here we check that /////

if($this1 < $nume) {

print "<a href='$page_name?start=$next&column_name=$column_name'><font face='Verdana' size='2'>NEXT</font></a>";}

echo "</td></tr></table>";

 

 

?>

</div>

 

</div>

 

</body>

 

</html>

 

 

 

 

Any help would be very much appreciated.

 

Regards

 

James

:D

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

When your generating the table, use a unique field (such as $noticia[id]) and either:

   a) Have a small one/two button form for each, with a 'hidden' containing that ref.

   b) Add a link with ?id=$noticia[id], type thing.

Then display appropriately!

 

 

So, would I simply add the ?id=$notica[id] to the following section:

 

echo "<tr >";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[id]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[companyname]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[section]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><a href=view_record.php?id=$notica[id]>View[/url]</font></td>";

echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><a href=edit_record.php?id=$notica[id]>Edit[/url]</font></td>";

 

Would this work?

 

Also, with regards to the one/two button form, would this replace the 'view' and 'edit' buttons that  I already have when the table is generated?

 

Regards

 

James

 

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.