Jump to content

help me please..


justndrow

Recommended Posts

guys, i've some data like

<table><th>name</th><th>tsm</th><th>anm</th><th>rpl</th><th>mm</th><th>kpr</th><th>tkj</th><th>tkr</th>
<tr><td>id_1</td><td>2.3459577830484</td><td>2.619896428578</td><td>2.5558371053771</td><td>2.4963700154674</td><td>2.4646111307953</td><td>2.5236872051792</td><td>2.4850274708961</td></tr>
<tr><td>id_2</td><td>2.5263997437825</td><td>2.5492707188906</td><td>2.4602344607999</td><td>2.4738884506176</td><td>2.4234629649285</td><td>2.5062728392821</td><td>2.3924560829401</td></tr>
<tr><td>id_3</td><td>2.3787642410781</td><td>2.4541833728022</td><td>2.3365975223888</td><td>2.3241313441239</td><td>2.4619716160792</td><td>2.3245813803686</td><td>2.3970696185661</td></tr>
</table>

so,, i ve problem.. how to make a selection student in class "tsm, anm, rpl . ...... tkr"

rules : 1. selecting from the largest value of owned student ( every student have 7 value), data student in here result.txt

           2. one person only entered in one class.

3. every class have limit limit.txt

4. students who exceed the limit value option transferred to subsequent owned

 

Link to comment
Share on other sites

Huh?

 

You don't make much sense to me. And posting a stream of code such as you did is not the way to encourage help. Good coders write their code in neat formats to make it easy to spot things, to make it easy to read and understand. Perhaps a better composed description of WTH you are trying to do would help too.

  • Like 1
Link to comment
Share on other sites

First and foremost, are you trying to display the database data in an HTML table, or do you actually have a string that comprises an HTML table and you're trying to extract data from the string? Looking at your attachments, it looks like you've got everything in a database, but it's good to be sure.

 

Let us see the code you've come up with so far and let us know what results you're getting and I'm sure you'll get pointed in the correct direction.

Link to comment
Share on other sites

Can't resist an interesting challenge. This is my interpretation of your problem and a possible solution

 

(Note that the top lines of the two text files need removing prior to processing so they contain just the relevant data)

$students= [];
$limits  = [];
$totals  = [];

$results = json_decode(file_get_contents('result.txt'),1);

/***************************************************************
* GET STUDENT DATA
* (store classes in score order (desc) for each student)
****************************************************************/

foreach ($results as $sdata) {
    $tmp = array_slice($sdata,1); // get array of just classes and scores
    arsort($tmp);
    $s = $sdata['id_siswa'];
    $students[$s] = array_keys($tmp);  // store classes in order of score
    $totals[$s] = array_sum($tmp);     // get total score for each student
}

/***************************************************************
* SORT TOTALS ARRAY TO GIVE STUDENT PROCESSING ORDER
* (students with highest total scores allocated first)
****************************************************************/
arsort($totals);

/***************************************************************
* GET CLASS LIMITS
****************************************************************/
$ldata = file('limit.txt');
foreach($ldata as $line) {
    list($c,$l) = explode(':',$line);
    $limits[trim($c)] = trim($l);
}

/***************************************************************
* ALLOCATE THE STUDENTS TO CLASSES
* if highest score class is full, try next until allocated
****************************************************************/
$classes   = array_fill_keys(array_keys($limits), []);

foreach ($totals as $sid=>$t) {
    foreach ($students[$sid] as $cls) {
        if (count($classes[$cls]) < $limits[$cls]) {
            $classes[$cls][] = $sid;
            break;                    // student allocated to class
        }
    }
}

/***************************************************************
* OUTPUT THE RESULTS
****************************************************************/
foreach ($classes as $cls => $studs) {
    echo "<strong>$cls</strong> " . count($studs) . " students (Limit : {$limits[$cls]})<br>";
    echo join(', ', $studs). '<br><br>';
}
  • Like 1
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.