Kirill Nagiev Kirill Nagiev - 1 month ago 4
MySQL Question

How to get and assign data for each row

So what i am trying to do is to get data from database and assign it for each process to allow user edit it.
Thats how I want it to look like:
[attached image][1]

But what I get is [here][2].
So as you can see it repeatedly displays on both processes.
So to get data and assign it to each process im doing this:

<div class="procLeader">
<div class="ui-widget-content">
<label>Leader:</label>
<ol>
<li class="placeholder" name="procLeader[]"><div class="adding">Add Process Leader here</div></li>
<?php
$result4 = getProcessLeader($projectNo);
if (!$result4) {
die('Invalid query: ' . mysqli_error($conn));
}
while($row4 = mysqli_fetch_array( $result4))
{
$procL[] = $row4['process'];
$procLeader[] = $row4['proc_leader'];
}

foreach( $procL as $proc => $eq )
{
$leader = $procLeader[$proc];
echo "<li class='dropClass'><span class='closer'>x</span>".$leader."</li>";
}
?>
</ol>
</div>
</div>


And
getProcessLeader
function:

function getProcessLeader($projectNo){
global $con;
$sql = "SELECT * FROM `proc_leader` WHERE projectNo='$projectNo' ";
return mysqli_query($con, $sql);
}


So how can I assign each person for exactly process? Thanks

EDIT



After using only while, i still got problem with names displaying for each process:Now it looks like this

<div class="procLeader">
<div class="ui-widget-content">
<label>Leader:</label>
<ol>
<li class="placeholder" name="procLeader[]"><div class="adding">Add Process Leader here</div></li>
<?php
$result4 = getProcessLeader($projectNo);
if (!$result4) {
die('Invalid query: ' . mysqli_error($conn));
}
while($row4 = mysqli_fetch_array( $result4))
{
$procL[] = $row4['process'];
//$procLeader[] = $row4['proc_leader'];

echo "<li class='dropClass'><span class='closer'>x</span>".$row4['proc_leader']."</li>";
}

?>
</ol>
</div>
</div>


But I need this

Answer

I am not sure why you have two loops here, you probably only need the one. If you keep building on the two arrays without resetting it, you are likely experiencing the result of that. Try just echoing in the while.

while($row4 = mysqli_fetch_array($result4)){  
    echo "<li class='dropClass'><span class='closer'>x</span>".$row4['proc_leader']."</li>";
}
Comments