hi guys, just wanna ask, is it possible to have a function using tables in html wherein if a user selects a row, the program will get the value of the entire selected row? and this value will be passed to php without reloading the page itself..thanks thanks in advance,^_^

Recommended Answers

All 6 Replies

Yes, all you need to do is give each row a unique id (eg number) and use ajax to make the php request.

could you give me some code in there??

This is a brief code...

echo '<table border=1 cellpadding=5 cellspacing=0>';
for ($i=0;$row=mysql_fetch_assoc($sql_result);$i++) {
echo '<tr id="'.$i.'">';
echo '<td>'.$row['column1'].'</td>';
echo '<td>'.$row['column2'].'</td>';
echo '<td><a href=# onclick="javascript:ajaxfunction(\''.$i.'\');">Send</a></td>';
}
echo '</table>';

sir, the code didnt work, it displays an error "Object required."

My code was just a brief outline that shows the hard stuff but all you need to do is create the ajax function with the row input and to do the mysql query. I would suggest following an ajax tutorial for that bit so you can get an understanding of how it works.

Possibly the error "Object required." will comes if you haven't created instance for the database or if you haven't created XMLHTTPREQUEST Object.

If you haven't created Ajax object then
javascript:ajaxfunction
will not works for you.

cwarn23 has given correct code for you.

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.