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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.