zgkhoo Posted October 29, 2007 Share Posted October 29, 2007 current i show mysql data in a table aim to make my own datagrid. but how to adding the delete feature by tick the checkbox and then press the "delete" button, then it will delete the record in mysql db too? and how to add the effect that when click on the record..then highlight the table's row? bellow is the screenshot of my datagrid .. thanks Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/ Share on other sites More sharing options...
zq29 Posted October 29, 2007 Share Posted October 29, 2007 You'd name all of your checkboxes the same thing: name="delete[]" The [] ensures that the checked boxes are sent as an array. Don't forget to give them unique values, a good choice would be the id of the row in the database. When processing, you can then just loop through your POSTed array and create a query: <?php $q = "DELETE FROM `table` WHERE "; foreach($_POST['delete'] as $id) $q .= "`id`='$id' AND "; $q = substr($q,0,-5); mysql_query($q) or die(mysql_error()); ?> As far as highlighting a row, not sure, JavaScript? Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380463 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 how about the edit link? which click this link then and editing each record's information. thanks.. is it any tutorial about this editing link/delete checkbox? i try hard to find these tutorial by google it..but nothing found. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380468 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 You'd name all of your checkboxes the same thing: name="delete[]" The [] ensures that the checked boxes are sent as an array. Don't forget to give them unique values, a good choice would be the id of the row in the database. When processing, you can then just loop through your POSTed array and create a query: <?php $q = "DELETE FROM `table` WHERE "; foreach($_POST['delete'] as $id) $q .= "`id`='$id' AND "; $q = substr($q,0,-5); mysql_query($q) or die(mysql_error()); ?> As far as highlighting a row, not sure, JavaScript? $_POST['delete'] as $id y use "as", wat it for? thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380471 Share on other sites More sharing options...
zq29 Posted October 29, 2007 Share Posted October 29, 2007 $_POST['delete'] as $id y use "as", wat it for? thanks.. foreach Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380474 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 $_POST['delete'] as $id y use "as", wat it for? thanks.. foreach u duno about how to code the editing hyperlink? Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380476 Share on other sites More sharing options...
darkfreaks Posted October 29, 2007 Share Posted October 29, 2007 you could do something like this http://www.velocityreviews.com/forums/t94167-highlight-row-in-datagrid.html Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380479 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 no edit link tutorial at all? it seem damn hard :-\ Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380501 Share on other sites More sharing options...
otuatail Posted October 29, 2007 Share Posted October 29, 2007 For the Edit you could create a sepeate page and in the link add ?rec=$ID where $ID is the reord number. Same as you would do for the value of the check boxes. Then create a (php only) update page, and redirct back to your table. Desmond Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380502 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 For the Edit you could create a sepeate page and in the link add ?rec=$ID where $ID is the reord number. Same as you would do for the value of the check boxes. Then create a (php only) update page, and redirct back to your table. Desmond thanks for your help do u got tutorial about this edit, or wat keyword should i google? fail to find it several time. ?rec=$ID <--this is get method? Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380509 Share on other sites More sharing options...
otuatail Posted October 29, 2007 Share Posted October 29, 2007 No Edit is something you have to write yourself. The edit.php file you write will have text boxes and textareas in it. You have to make the changes and hit a submit button., to a php page like updaterec.php. and create a SQL UPDATE command Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380513 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 ?rec=$ID this is the GET method? Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380520 Share on other sites More sharing options...
otuatail Posted October 29, 2007 Share Posted October 29, 2007 Yep. Shouldn't be too difficult to put together. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380525 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380531 Share on other sites More sharing options...
Barand Posted October 29, 2007 Share Posted October 29, 2007 When processing, you can then just loop through your POSTed array and create a query: <?php $q = "DELETE FROM `table` WHERE "; foreach($_POST['delete'] as $id) $q .= "`id`='$id' AND "; $q = substr($q,0,-5); mysql_query($q) or die(mysql_error()); ?> Hmm! Think you meant 'OR' instead of 'AND'. Alternative <?php $ids = join (',', $_POST['delete']) $q = "DELETE FROM table WHERE id IN ($ids)"; Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380593 Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 how about delete checkbox , edit link feature integrate with pagination? is it hard? thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380597 Share on other sites More sharing options...
zgkhoo Posted October 30, 2007 Author Share Posted October 30, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380827 Share on other sites More sharing options...
Barand Posted October 30, 2007 Share Posted October 30, 2007 The code for delete checkbox , edit link feature is exactly the same whether you paginate or not. is it hard? Same with everything. If you know what you are doing, no. If you don't, yes. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380832 Share on other sites More sharing options...
zgkhoo Posted October 30, 2007 Author Share Posted October 30, 2007 For the Edit you could create a sepeate page and in the link add ?rec=$ID where $ID is the reord number. Same as you would do for the value of the check boxes. Then create a (php only) update page, and redirct back to your table. Desmond where can i learn this ink add ?rec=$ID where $ID is the reord number.??? wat this technique called? i wanna go research for it. Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380838 Share on other sites More sharing options...
Barand Posted October 30, 2007 Share Posted October 30, 2007 wat this technique called? query string Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380839 Share on other sites More sharing options...
zgkhoo Posted October 30, 2007 Author Share Posted October 30, 2007 thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/#findComment-380843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.