count usage

Hi guys,

i need some help here… i doing a small project that i need to count how many person in a group. i have a limit 15 each group and when the first group is over 15 people, it will automatic assign to second group. i may have more then 500 people in my user list. so what is the solution for that??? i kind of stuck…i only manage to start with something like this

[php]if ((count($group_id) = > 15) == 0) {
// do something
}[/php]

Elvatra,

I think we need a little more information, sounds like you have a list of around 500 users, is that list in a database? Where are you storing the groups, are you putting that back in the database?

hi,

i would like to store the grouping in a table. so that, when i call out the group, it will able to list group 1 which is the first 15 people and group 2 etc…

i hv a grouping table which list the user id group number.

Sounds like you have a little work to do…

  1. You have a database table of 500+ users, you need to query against that database and select all the users.
  2. You need to create a “Group” Table with a “GroupID and Group Name”
  3. You need to create a “GrooupUser” database table that has 2 columns “GroupID”, and “User ID”
  4. You then need to loop through the 500 users and add 15 users to each group you make up in the database
  5. Then you most likely need to display it.

Once you get all those parts together, it’ll be easier for people to help you. Sounds like you’re going to have a lot of questions accomplishing each part.

  1. You have a database table of 500+ users, you need to query against that database and select all the users.
  2. You need to create a “Group” Table with a “GroupID and Group Name”
  3. You need to create a “GrooupUser” database table that has 2 columns “GroupID”, and “User ID”
  4. You then need to loop through the 500 users and add 15 users to each group you make up in the database
  5. Then you most likely need to display it.

Once you get all those parts together, it’ll be easier for people to help you. Sounds like you’re going to have a lot of questions accomplishing each part.

ok.

  1. i hv create a Group table with GroupID and group name.
  2. i hv also create a group user table with group id and user id

the problem is i dunno how to put it all together.

so in order not to waste place at here. i hv another question too… im currently doing having upload picture to the database. this is no problem on me. i hv done it. but there is a problem that when uploading the picture, i hv 2 more field i need to insert to database but is in another table. which mean i hv a table for picture and another table for user which this user table keeping username and description. So how do i do that?? i did not use any framework to work it out.

Just do two separate insert statements, one for the photo table and one for the user table.

hi, i have done some of my code to update the row of one table… when i fetch the data, it display the correct data. theres no problem on here… but after i modify the data, it will not update on my table. instead of update single column of single row, it wipe out all the remain column…

so here is my php code
[php]if (!$_REQUEST) {
} else {
if (isset($_REQUEST[‘upload’])) {

     foreach ($_GET['id']as $rowid ) { 

//$id = $user_id[$rows[‘id’]];

$company_address = $_POST[company_address];
$tel = $_POST[tel];
$mobile = $_POST[mobile];
$email = $_POST[email];
$incharge = $_POST[incharge];

$update = “UPDATE customer SET company_address = ‘$company_address’, tel = ‘$tel’, mobile = ‘$mobile’, incharge = ‘$incharge’, email = ‘$email’ WHERE id = $rowid”;
var_dump($update); exit;
$result_update = mysql_query($update);

header(“Location: edit_client.php?result_update=”.$result_update."");

echo “
Files updated
”;

	}
}

}
$id = $_GET[id];
$query = “SELECT * FROM customer WHERE id = ‘$id’”;
$result = mysql_query($query);
$row = mysql_fetch_assoc($result); [/php]

my update form code

[code]

    <tr>
      <td></td>
      <td align="right"><input type="submit"
      name="upload value="upload"></td>
    </tr>
id : " disabled = "disabled">
Customer ID : " disabled = "disabled">
Name : " disabled = "disabled">
Address: ">
Phone Number: ">
Mobile: ">
Person In Charge: ">
E-mail: ">
[/code] all i want is to update the specific column and row information where clause is equal to the row id. if not, i nd to do a checkbox so that is equal to the id.

may i know what is wrong with my coding.

You didn’t put your form names in quotations when you are retrieving them.

Change:

[php] $company_address = $_POST[company_address];
$tel = $_POST[tel];
$mobile = $_POST[mobile];
$email = $_POST[email];
$incharge = $_POST[incharge];[/php]

To:

[php] $company_address = $_POST[‘company_address’];
$tel = $_POST[‘tel’];
$mobile = $_POST[‘mobile’];
$email = $_POST[‘email’];
$incharge = $_POST[‘incharge’];[/php]

hi

i still getting no update in mysql table…

i already fix the quotation on it.

and also my foreach statement are wrong.

Warning: Invalid argument supplied for foreach()

what lead to this problem???

You’re doing a

[php]foreach ($_GET[‘id’]as $rowid ) { [/php]

but in your HTML you have this…

[php]name=“user_id[{$rows[‘id’]}]” [/php]

They don’t match… You’ll have to re-structure that part of your code on how you are retrieving your Users ID’s from the HTML.

hi Topcoder

i hv change to this

[php]foreach ($_REQUEST[‘user_id’] as $rowid ) [/php]

[php]name="user_id[{$rows[‘id’]}][/php]

but i still getting

Warning: Invalid argument supplied for foreach()

I kind of want you to try to realize what I’m saying and try to accomplish it on your own. When I say you need to restructure how you are retrieving your user Ids…

Change:

[php]

Customer ID : " disabled = "disabled"> [/php]

To:

[php]

Customer ID : " disabled = "disabled"> [/php]

What that does is create a HTML array for user_id - Before you had unique values.

Then you need to cycle through the HTML array in your “for each” statement.

Change:

[php] foreach ($_GET[‘id’]as $rowid ) { [/php]

To:

[php] foreach ($_POST[‘user_id’] as $rowid) {[/php]

Since you are posting it back as seen here.

[php] [/php]

You need to use $_POST and not $_GET, as seen above in $_POST[‘user_id’] . If you try understand the code and the language everything becomes easy. Just trying to get something to work, just leads to frustration.

thats why i trying to understand the code. due to im new to php. i making a sample form upload in order to understand it. im learning by myself which no attending any courses…

by the way, i have change to what you have told me. but i still getting invalid argument foreach

if you look at your HTML

[php]<input type=“submit” name="upload value=“upload”>[/php]

You don’t have a closing quote for your name value, not saying that’s the issue that you’re having, but it is an issue…

I also mocked up a sample page and my code works fine, try it yourself

[php]<?php

if (isset($_POST[‘upload’])) {

foreach ($_POST[‘user_id’] as $rowid) {
echo $rowid;
echo “
”;
}

}

?>

[/php]

strange. i hv closing quote on my every value name.

is just that when i post to here, if delete my codes…

[php]

    <tr>
      <td></td>
      <td align="right"><input type="submit"
      name="upload" value="upload"></td>
    </tr>
Customer ID : " disabled = "disabled">
Name : " disabled = "disabled">
Address: ">
Phone Number: ">
Mobile: ">
Person In Charge: ">
E-mail: ">
[/php]

[php]mysql_connect($server,$db_user,$db_pass);
if (!$_REQUEST) {
} else {
if (isset($_REQUEST[‘upload’])) {

       foreach (isset($_POST['user_id']) as $rowid ) { 

//$user_id=$_GET[‘user_id’];
$company_address = $_POST[‘company_address’];
$tel = $_POST[‘tel’];
$mobile = $_POST[‘mobile’];
$incharge = $_POST[‘incharge’];
$email = $_POST[‘email’];

$update = “UPDATE customer SET company_address = ‘$company_address’, tel = ‘$tel’, mobile = ‘$mobile’, incharge = ‘$incharge’, email = ‘$email’ WHERE user_id = $rowid”;

$result_update = mysql_query($update);
echo $result_update;
//header(“Location: edit_client.php?update=”.$result_update."");

//var_dump($result_update); exit;
//echo “
Files updated
”;
}
}
}[/php]

i still having problem on it…

Your HTML doesn’t make sense.

You’re referencing

[php]

<input type=“text” name=“user_id[]” size=“20” value="<?php echo "$row[user_id]" ?>" disabled = “disabled”>[/php]

Specifically

[php]<?php echo "$row[user_id]" ?>[/php]

I don’t see where you create $row?

If you right click on your HTML page before you press submit and click view source, I think you will be surprised what you see. Maybe you should post that.

Are you editing 1 client at a time or many clients at once?

I’m assuming you are doing many at once, but I can be wrong.

If you’re doing many at once, your other input fields need to be arrays like user_id, if it’s one at a time, then you don’t need arrays at all.

ok, i think you misunderstand it…

i screenshot the step of my whole process along with the codes.

first, is viewing all the client list which is call view_client.php

[php]<?php
session_start();
if(isset($_SESSION[‘user’]) && !empty($_SESSION[‘user’])){
echo "You are Welcome ". $_SESSION[‘user’];

?>

<?php include 'config.php'; mysql_connect($server,$db_user,$db_pass); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM customer"; $result=mysql_query($query); mysql_close(); while ($row=mysql_fetch_array($result)){ echo (""); echo (""); echo (""); echo (""); echo (""); echo (""); echo (""); echo (""); } echo "
ID Company Name Address Tel E-mail Phone person In Charge
$row[id]$row[company_name]$row[company_address]$row[tel]$row[email]$row[mobile]$row[incharge]Edit
"; ?> <?php }else{ header("location:login.php"); } ?>[/php]

===============================================================

Ok here is the edit_client.php

here is the full codes of edit_client.php

[php]<?php
session_start();
if(isset($_SESSION[‘user’]) && !empty($_SESSION[‘user’])){
echo "Welcome ". $_SESSION[‘user’];

//include 'tabmenuOneForAll.php';

?>

<?php include 'config.php'; mysql_connect($server,$db_user,$db_pass); if (isset($_POST['upload'])) { foreach ($_POST['user_id'] as $rowid ) { //$user_id = $_POST['user_id']; $company_address = $_POST['company_address']; $tel = $_POST['tel']; $mobile = $_POST['mobile']; $incharge = $_POST['incharge']; $email = $_POST['email']; $update = "UPDATE customer SET company_address = '$company_address', tel = '$tel', mobile = '$mobile', incharge = '$incharge', email = '$email' WHERE id = $rowid"; $result_update = mysql_query($update); echo $result_update; //header("Location: edit_client.php?update=".$result_update.""); //var_dump($result_update); exit; //echo "
Files updated
"; } } $id = $_GET[id]; $query = "SELECT * FROM customer WHERE id = '$id'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); //header("Location: edit_client.php?update=".$result.""); //header("Location: view_client.php"); ?>
    <tr>
      <td></td>
      <td align="right"><input type="submit"
      name="upload" value="upload"></td>
    </tr>
id : " checked = "checked" disabled = "disabled">
Customer ID : " disabled = "disabled">
Name : " disabled = "disabled">
Address: ">
Phone Number: ">
Mobile: ">
Person In Charge: ">
E-mail: ">
<?php }else{ header("location:login.php"); } ?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service