Remove Table Row - Selected Users

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Remove Table Row - Selected Users

Post by synical21 »

Hey Gurus i have a problem i can not solve, i can not even begin to understand the theory to make this work so i can not start. I will explain the problem, i have a table created in php like so:

Code: Select all

// START AN OUTPUT TABLE
echo "<table class='sample5'>";	  
// TITLE FOR COLUMNS
    echo "<tr><td nowrap><b>Job Title</b></td><td align='center'><b>Edit</b></th><td align='center'><b>Status</b></th><td align='center'><b> Finished</b></th><td align='center'><b>View</b></th></tr>";
 
// ITERATE OVER THE RESULTS SET
    while ($line = mysql_fetch_assoc($result)) 
    {
// GET EASY-TO-READ LOCAL VARIABLES    
        foreach ($line as $key => $val) { $$key = htmlentities($val); }
// CREATE THE ROW OF DATA     

        echo "<tr>";
        echo "<td width='50%'><a href='jobinfo.php?ID=$job_id'>" . substr($title,0,45) . "</a> </td>\n";
		echo "<td width='10%' align='center'><a href='edit.php'><img src ='images/edit.gif'></a></td>\n";
		// echo "<td width='10%' align='center'>$" . $perperson . "</td>\n";
		echo "<td width='10%' align='center'>"; if ($approved == 0)
		{ 
		echo "<span style='color:#FF5F00;'><b>Pending</b></span>";
		}
		else{
			
		echo "<img src ='images/statusrun.png'>";
		}
		"</img></td>\n";
        echo "<td width='10%' align='center'><font color = 'green'><b>$amountcomplete</font></b></td>\n";
        echo "<td width='20%' align='center'><a href=$job_id'><u>View </a></u></td>\n";
    } // END WHILE ITERATOR
    echo "</table>\n";
The table creates rows and each row has a unique job id, some users want some jobs to not show in this table ( like an ignore button i guess) so how would i make the table not show rows when users select that row to not appear, i know it can be done i just cant think of the logic :(

So in short:

1. How can a user select a row/job id not to show in the table
2. How can the table react to that selection to not show the row/job id selected to ignore.

Hope its clear, thanks for reading.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Remove Table Row - Selected Users

Post by yacahuma »

is the person going to hide them forever, like a delete?
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Remove Table Row - Selected Users

Post by synical21 »

yacahuma wrote:is the person going to hide them forever, like a delete?

Yup like a delete, but a delete just for that user.
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Remove Table Row - Selected Users

Post by lunarnet76 »

hi,

you can simply add a checkbox to every row and when submitted it put all the $job_id in an array in session or if you want it to be permanent create a new table in your database!
tell me if you want more details^^
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Remove Table Row - Selected Users

Post by synical21 »

lunarnet76 wrote:hi,

you can simply add a checkbox to every row and when submitted it put all the $job_id in an array in session or if you want it to be permanent create a new table in your database!
tell me if you want more details^^

Ah yes great idea i like the permanent way by creating a new table, i understand it pretty much just the array what confuses me. A little more detail would help me alot so i can start this task :) thank you for the suggestion i like it.

Im guessing the data will be stored in the table like "user_id" "job_id", then run a query with the current user id to find which jobs are being deleted/ignored. so now there will be E.G 40 records with different job_ids wanting to be ignored. how could i make the table query ignore them job_ids. Im obviously wrong so a little guidence would help.
Last edited by synical21 on Sun Apr 11, 2010 7:05 pm, edited 1 time in total.
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Remove Table Row - Selected Users

Post by lunarnet76 »

well you simply name your checkboxes like

Code: Select all

<input type="checkbox" name="selected[<?php echo $job_id;?>]"/>

then with PHP

Code: Select all

if(isset($_REQUEST['selected'])){
if(!isset($_SESSION['jobId']))$_SESSION['jobId']=array();
foreach($_REQUEST['selected'] as $jobId)
$_SESSION['jobId'][$jobId]=true;
}

and then when you show the line again

Code: Select all

while ($line = mysql_fetch_assoc($result)) 
    { if(isset($_SESSION['jobId'][$line['job_id']])continue;
so it's skip the line!
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Remove Table Row - Selected Users

Post by yacahuma »

you are going to need to tables in your design. One is the data table and the other the user_viewed_table

EX
DATA_ID| DATA
1 DATA1
2 DATA2


VIEW TABLE(JUST KEEP THE HIDDEN ONES)
USER_ID | DATA_ID
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Remove Table Row - Selected Users

Post by lunarnet76 »

you seem desperate so here is the solution

Code: Select all


<table class="sample5">  
    <tr>
		<th nowrap><b>Job Title</b></th>
		<th align="center"><b>Edit</b></th>
		<th align="center"><b>Status</b></th>
		<th align="center"><b> Finished</b></th>
		<th align="center"><b>View</b></th>
        <th align="center"><b>Ignore</b></th>
	</tr>
 <?php
 $userId=17;
 if(isset($_REQUEST['ignore'])){
	mysql_query('INSERT INTO jobs_viewed(user,job) VALUES('.(int)$userId.','.(int)$_REQUEST['ignore'].')');
}

 
 $result=mysql_query('
	SELECT
		job_id,
		title,
		perperson,
		approved,
		amountcomplete
	FROM 
		jobs j
	 	LEFT JOIN jobs_viewed jv ON jv.job=j.id AND jv.user='.$userId.'
	WHERE
		jv.user IS NULL
	LIMIT 10
')or die(mysql_error());
// ITERATE OVER THE RESULTS SET
    while ($line = mysql_fetch_assoc($result)) {
// GET EASY-TO-READ LOCAL VARIABLES    
        foreach ($line as $key => $val) { $$key = htmlentities($val); }
// CREATE THE ROW OF DATA  
        ?><tr><td width="50%"><a href="jobinfo.php?ID=<?php echo $job_id;?>"><?php echo substr($title,0,45);?></a> </td>
                <td width="10%" align="center"><a href="edit.php"><img src ="images/edit.gif" /></a></td>
                <td width="10%" align="center"><?php echo $perperson;?></td>
                <td width="10%" align="center">
                <?php echo $approved == 0? '<span style="color:#FF5F00;"><b>Pending</b></span>':'<img src ="images/statusrun.png" />';?>
                </td>
        		<td width="10%" align="center"><font color = "green"><b><?php echo $amountcomplete;?></font></b></td>
       			<td width="20%" align="center"><a href="<?php echo $job_id;?>"><u>View</u></a></td>
                <td width="20%" align="center"><a href="<?php echo $_SERVER['PHP_SELF'].'?ignore='.$job_id;?>"><u>Ignore</u></a></td>
    <?php
    } 
?></table>
of course you have to replace $userId by the good userId and create a table like

Code: Select all

CREATE TABLE IF NOT EXISTS `jobs_viewed` (
  `user` int(10) NOT NULL,
  `job` int(10) NOT NULL,
  PRIMARY KEY (`user`,`job`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Post Reply