Ok I am working something that I have seen others do and that is to echo out a form table and what I am
trying to do is to get the data that is not assigned to a user and allow the admin to assign it to the user. I cannot get it to clear the table when it is assigned and run the query to only display the un-assigned ones. I may be wrong in doing this but I was trying to do something different. Any one have any suggestions.

                                do 
                                  { 
                                    echo '<option value="',$row_rsinspector['contact_id'],'">',$row_rsinspector['Inspector'],'</option>';
                                    $id_inspector =$row_rsinspector['contact_id'];
                                  }while ($row_rsinspector = mysql_fetch_assoc($rsinspector));
                                    $rows = mysql_num_rows($rsinspector);
                                      if($rows > 0) 
                                        {
                                          mysql_data_seek($rsinspector, 0);
                                          $row_rsinspector = mysql_fetch_assoc($rsinspector);
                                         }
                               echo '</select></td>';
                               echo '<td width="%"><input type="submit" value="Submit"/></td>';}
                              echo '</form></td></tr>';

                            echo '</table>';

                       ?>

The update database is done using the following:

if(isset($_POST['id_inspection'], $_POST['inspector']))
{
  $idinspection = $_POST['id_inspection'];
  $id_inspector = $_POST['inspector'];  
  mysql_query("UPDATE inspection SET idemployee ='$id_inspector',last_modified = now(), assigned ='0'
  WHERE idinspection ='$idinspection';");
}
Member Avatar for LastMitch

I cannot get it to clear the table when it is assigned and run the query to only display the un-assigned ones. I may be wrong in doing this but I was trying to do something different. Any one have any suggestions.

I don't see a table but I do see a form being echoing out.

Is your database connected to your query?

if(isset($_POST['id_inspection'], $_POST['inspector']))

Why do you have 2 $_POST in the isset statement like? You know there's another way to doing that more nice but as long as it works. It's fine.

I have the database tied to the query. I would love to know of better ways to make the code easier.

Member Avatar for LastMitch

I have the database tied to the query. I would love to know of better ways to make the code easier.

I got no idea what you are trying to do here (explain to me what are you trying to do?):

do{
echo '<option value="',$row_rsinspector['contact_id'],'">',$row_rsinspector['Inspector'],'</option>';

$id_inspector =$row_rsinspector['contact_id'];

}while ($row_rsinspector = mysql_fetch_assoc($rsinspector));

$rows = mysql_num_rows($rsinspector);

if($rows > 0){
mysql_data_seek($rsinspector, 0);

$row_rsinspector = mysql_fetch_assoc($rsinspector);
}

echo '</select></td>';
echo '<td width="%"><input type="submit" value="Submit"/></td>';}
echo '</form></td></tr>';
echo '</table>';
?>

This code I change it a little:

From this:

if(isset($_POST['id_inspection'], $_POST['inspector']))
{
$idinspection = $_POST['id_inspection'];
$id_inspector = $_POST['inspector'];
mysql_query("UPDATE inspection SET idemployee ='$id_inspector',last_modified = now(), assigned ='0' WHERE idinspection ='$idinspection';");
}

to this (it looks more clean):

if (isset($_POST['id_inspection']) && isset($_POST['inspector'])){
$idinspection = $_POST['id_inspection'];
$id_inspector = $_POST['inspector'];
mysql_query("UPDATE inspection SET idemployee ='$id_inspector',last_modified = now(), assigned ='0' WHERE idinspection ='$idinspection';");
}

LastMitch, Thanks for the responce, I The echo option value allows one to pick from a list of persons to insert into the database by the Contact ID of the user. The table populates the list of forms for each contact info, it is to allow for adminstration user to assign a task to a specific contact and then upon click of submit, it updates the database with the contact id and changes the assigned value from 1 to 0 so that it will not show back up in the list upon refreshing. The problem is that when it refreshes it will not disappear for some reason. I have been working on this for a while trying to figure it out why.

Member Avatar for LastMitch

The problem is that when it refreshes it will not disappear for some reason. I have been working on this for a while trying to figure it out why.

Does it involve jQuery or javascript?

This function: mysql_data_seek doesn't work anymore.

Read this:

http://php.net/manual/en/function.mysql-data-seek.php

I think you need to update some terms. 1 term is fine I can make adjustments but 2 or more is not good that's a bit too much work.

This all I can do:

echo '<option value="',$row_rsinspector['contact_id'],'">',$row_rsinspector['Inspector'],'</option>';
$id_inspector =$row_rsinspector['contact_id'];
}while ($row_rsinspector = mysql_fetch_assoc($conn,$id_inspector));
$rows = mysql_num_rows($conn,$rsinspector);
if($rows > 0){
mysql_data_seek($rsinspector, 0);
$row_rsinspector = mysql_fetch_assoc($conn,$rsinspector);
}
echo '</select></td>';
echo '<td width="%"><input type="submit" value="Submit"/></td>';}
echo '</form></td></tr>';
echo '</table>';

On my local host this function mysql_data_seek doesn't work at all.

The connections works but not these query:

mysql_num_rows
mysql_fetch_assoc

In order to function you need to add an connection (this not the way of doing this):

mysql_fetch_assoc($conn, $id_inspector)
mysql_num_rows($conn, $rsinspector)
mysql_fetch_assoc($conn, $id_inspector)

Another words you need to update some terms and you need to used mysqli functions instead.

Thanks I will look into mysqli, The current code will reviel off my server I am not testing local. But thanks for the input.

Member Avatar for LastMitch

Thanks I will look into mysqli, The current code will reviel off my server I am not testing local. But thanks for the input.

It really depend which PHP you have on your server and on your local host.

I have both the same PHP on my server and local host.

If you client has a different version then those bugs will pop up and you will have a hard time transfering.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.