Jump to content

[SOLVED] Member List Edit


dfowler

Recommended Posts

Hey guys,

I have a member list that an admin will be able to edit member's information.  My problem is broken down into two questions, first here is the code:

<?php
$Page = 'manage-customers';
include 'header.php';

if (!($limit)){
     $limit = 10;
}

if (!($page)){
     $page = 0;
}

$numresults = mysql_query("select * from users");

$numrows = mysql_num_rows($numresults);

/* not needed...
if ($numrows == 0){
     echo("No results found");
     exit();
}
*/

$pages = intval($numrows/$limit); 

if ($numrows % $limit) {
$pages++;
} 

$current = ($page/$limit) + 1;

if (($pages < 1) || ($pages == 0)) {
$total = 1;
} else {
$total = $pages;
} 

$first = $page + 1;

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;
} else {
$last = $numrows;
}

$resource = "select * from users order by name ASC LIMIT $page, $limit";
$customers = array();
$result = mysql_query($resource);
while (($row = mysql_fetch_assoc($result)) !== false) {
$customers[] = $row;
}

$counter=1;

?>

		<div id="app-page-title">
			Manage Registered Customers
		</div>
<div>
		<form action="user/user2.php" method="post" id="customer-search-form">
			<label for="customer">Customer Name</label>
			<input type="text" name="customer" class="customer-name-field" />
			<input type="submit" name="submit" value="Search" class="search-submit" />
		</form>
		</div>
		<br /><br />
		<div style="padding-left:10px;">
			<?php foreach($customers as $c) {
				echo $counter.".  ".$c['name']." - ".$c['email']." - ".$c['phone']."<br />";
				$counter++;
			} ?>

			<p align="center">
				<?php if ($page != 0) { 
					$back_page = $page - $limit;
					echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a>    \n");
				}

				for ($i=1; $i <= $pages; $i++) {
					$ppage = $limit*($i - 1);
				if ($ppage == $page){
					echo("<b>$i</b>\n");
				} else {
					echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
				}

				if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { 
					$next_page = $page + $limit;
					echo("    <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>");
				} ?>
			</p>
		</div>


		<div class="clear"></div>

<?php
include '/home/debisres/debisrestaurant.com/html/redsatin/meal_ticket/includes/app-footer.php';
?>

 

Question 1 - I want to have the alphabet displayed at the top and when the admin clicks on B it shows the names that start with B.  Can this be done without creating a whole other page?

 

Question 2 - I want each name to have an edit link after them that takes them to a page that will allow the admin to edit their information.  How do I send the information from that specific user to the next page since I am dynamically populating the list?

 

 

Thanks for any help!

Link to comment
Share on other sites

Ok, I'll answer question 2 as that's the easiest.

 

When you're making the link, just include the users unique ID in the URL (so you can retrieve it via a _GET), example http://yoursite.com/edit.php?id=5, then you can retrieve the users information on the edit page based on their unique id (5 in this case).

 

As for question 1, if you're wanting to display the list by the first letter, you could just do the same as above to be get which letter it would be, so retrieve it via $_GET.  Then in your sql query, do something like this:

 

<?php

$letter = $_GET['letter'];

$query = "SELECT * FROM users WHERE username LIKE '".$letter."%'";

?>

 

There's a nicer way to do it via regex, but I think that's quite a simply way :)

Link to comment
Share on other sites

Ok, I'll answer question 2 as that's the easiest.

 

When you're making the link, just include the users unique ID in the URL (so you can retrieve it via a _GET), example http://yoursite.com/edit.php?id=5, then you can retrieve the users information on the edit page based on their unique id (5 in this case).

 

As for question 1, if you're wanting to display the list by the first letter, you could just do the same as above to be get which letter it would be, so retrieve it via $_GET.  Then in your sql query, do something like this:

 

<?php

$letter = $_GET['letter'];

$query = "SELECT * FROM users WHERE username LIKE '".$letter."%'";

?>

 

There's a nicer way to do it via regex, but I think that's quite a simply way :)

 

That worked great with the edit feature!  Here is my concern with the second part, won't that pull all names with that letter in them?  I want it to be restricted to only names starting with the letter.

Link to comment
Share on other sites

Nope it won't.  The % sign is after the letter, so it'll only match names where it is that letter at the start.  Like I said you could use regex, which would look something like:

 

<?php

$query = "SELECT * FROM users WHERE username REGEXP '^".$letter."'";

?>

 

I'm not great with regex but I think that's right, the ^ indicates starts with.

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.