Jump to content

Incrementing a PHP loop with JS


MesaFloyd

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/198226-incrementing-a-php-loop-with-js/
Share on other sites

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.