MesaFloyd Posted April 11, 2010 Share Posted April 11, 2010 I am an <older> rookie, please be gentle with me. I make a table called from a DB using PHP The table loops the DB untill all the occupied fields are displayed - works fine - I am trying to insert a button for each row (JS), that when pressed will highlight and copy to clipboard one particular cell of that row The button is not working properly. When I press any of the buttons on the table, only the first cell is higlighted and copied. I know it is because all the buttons are calling the same cell, but I don't know how to make the button increment for that row. I then added the $i= statement now I get and error message when any of the buttons are pushed You can see it here... http://almcom.net/iponthego/viewdatabase-testbutton-help.php Any of you programming gru's able to help me. - yes, I know this will only work in IE - I think the solution is in JS, but I am not sure if it can be fixed in PHP. Please keep it simple for me. Thanks in advance Floyd <script language='Javascript'> function doact(d) { var doc = eval("document.readme."+d); cp = doc.createTextRange(); doc.focus(); doc.select(); cp.execCommand("Copy"); } </script> <form name="readme"> <?php include("database.php"); $query = "SELECT * FROM users"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Username</th> <th>IP Address</th><th>Email Address</th> <th>Last Visit Date-Time </th></tr>"; // keeps getting the next row until there are no more to get $i=1; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['username']; echo "</td><td>"; ?> <TEXTAREA name="text<?php echo $i++; ?>" style="width: 150px; height: 20px;" > <?php echo $row['pcidip']; ?> </TEXTAREA> <!-- <input onclick="doact('text1')" type="button" value="Copy IP"> --> <input onclick="doact('text<?php echo $i++; ?>')" type="button" value="Copy IP"> </form> <?php echo "</td><td>"; echo $row['email']; echo "</td><td>"; echo $row['datetime']; echo "</td></tr>"; } echo "</table>"; ?> I added the $i= statement to increment the loop but it does not do the trick. I am missing something you might see. Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/ Share on other sites More sharing options...
teamatomic Posted April 11, 2010 Share Posted April 11, 2010 Before you start the loop you need to give $i a value $i=0; otherwise you are incrementing nothing. oops you di. missed it. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040037 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2010 Author Share Posted April 11, 2010 Thanks HTH Please notice that I did put $i=1 just before the 'while' statement. I just now changed it to $i=0, but no joy... Floyd Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040039 Share on other sites More sharing options...
teamatomic Posted April 11, 2010 Share Posted April 11, 2010 increment is ++ not + HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040040 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2010 Author Share Posted April 11, 2010 Hi Again HTH Notice that my statments already are: text<?php echo $i++; ?> So it should be correct... correct? Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040043 Share on other sites More sharing options...
teamatomic Posted April 11, 2010 Share Posted April 11, 2010 What about in the javascript? HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040050 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2010 Author Share Posted April 11, 2010 Not sure what you mean. Could you point it out to me please. Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040057 Share on other sites More sharing options...
teamatomic Posted April 11, 2010 Share Posted April 11, 2010 var doc = eval("document.readme."+d); HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040062 Share on other sites More sharing options...
MesaFloyd Posted April 11, 2010 Author Share Posted April 11, 2010 I am still a dummy, What am I suppose to do with that? var doc = eval("document.readme."+d); is already there... what so you suggest I change. Please understand, I am not very good at programming, just learning I come from a hardware background. thanks for Helping Quote Link to comment https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/#findComment-1040068 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.