darkfox Posted November 21, 2012 Share Posted November 21, 2012 so this is the scenario, i am creating an admin page using php and html and i do have an HTML table that is being populated dynamically, so what i want to do is, when i click the table row, i will be redirected to another page and print the details of the product i clicked from the table. i really got lost here.. i dont really need the whole code/answer, i just need to know how to extract the text that is clicked from the table thanks in advance guys! Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/ Share on other sites More sharing options...
Muddy_Funster Posted November 21, 2012 Share Posted November 21, 2012 to answer that we would need an example of the data that is in the table Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394243 Share on other sites More sharing options...
darkfox Posted November 21, 2012 Author Share Posted November 21, 2012 this is the table it self, product id product name quantity amount 50 mouse 3 1000 50 cpu 45 800 50 sticker 5 50 50 keyboard 3 200 so how can i get the product id that was clicked? thank you sir Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394248 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2012 Share Posted November 21, 2012 Your would form a link with a GET parameter on the end of it, something like ?id=123, where the 123 is the product id and is dynamically put into each link as you loop through the data to output the html table. Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394251 Share on other sites More sharing options...
Muddy_Funster Posted November 22, 2012 Share Posted November 22, 2012 Yeah, exactly what he said, just tell us you don't actualy have 4 products with the same product id.... Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394256 Share on other sites More sharing options...
darkfox Posted November 22, 2012 Author Share Posted November 22, 2012 ahm sir can you elaborate further? i dont really get it.. sorry im still newbie in web programming Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394258 Share on other sites More sharing options...
Muddy_Funster Posted November 22, 2012 Share Posted November 22, 2012 ok, lets take it back to the start, how does the info get into the HTML table and where does it come from? Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394261 Share on other sites More sharing options...
PFMaBiSmAd Posted November 22, 2012 Share Posted November 22, 2012 There's nothing to elaborate on. As you are looping to dynamically make the existing html table, you produce a link with the indicated get parameter on it. If you can echo the product id in the that column of the html table, you can echo it in the link. Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394263 Share on other sites More sharing options...
darkfox Posted November 22, 2012 Author Share Posted November 22, 2012 ahm from my database sir.. ahm i am using MySQL.. Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394264 Share on other sites More sharing options...
darkfox Posted November 22, 2012 Author Share Posted November 22, 2012 sir my main problem is that, i cant get the product id that was clicked by the user.. Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394265 Share on other sites More sharing options...
Muddy_Funster Posted November 22, 2012 Share Posted November 22, 2012 what he's saying is that then you are echoing out the table contents make a lint that includes the product id as a url variable that the recieving page can then lookup. while($row = mysql_fetch_assoc($result)){ echo "<tr><td><a href=\"path_name/filename.php?pid={$row['product id']}\">{$row['product id']}</td><td>{$row['product name']}</td><td>{$row['quantity']}</td><td>{$row['ammount']}</td></tr> } That will then pass the product id through to the receiving page which can access it through the $_GET['pid'] call. Does that make more sense? Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394306 Share on other sites More sharing options...
darkfox Posted November 22, 2012 Author Share Posted November 22, 2012 oh.. ok sir, now that make sense! thanks alot sir! i owe you one and sir btw, how can i make it as a javascript code? coz i made an onclick function on <tr> so that i will not be using the '<a>' link to make it more presentable and make all columns clickable sir , do you have any idea? sorry for lots of questions sir.. thanks again ) Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394524 Share on other sites More sharing options...
Christian F. Posted November 22, 2012 Share Posted November 22, 2012 Use both, that way you know it'll work regardless of what browser your users use. I also recommend doing the page without the JS methods first, so that you don't try to do too much at the same time. JS can easily be added into the mix after everything's up and running, after all. Lastly, I'd probably look into jQuery for this, if I were you; It'll help make things easier for you in the long run, but only if you've read up on basic Javascript syntax first. Quote Link to comment https://forums.phpfreaks.com/topic/271005-how-to-get-data-from-html-table/#findComment-1394537 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.