On 2/9/2013 10:51 PM, Ethan Rosenberg, PhD wrote:
I know that this might be an Ajax/Javascript question. Hopefully you
can help. I do not know of any other source for good info.
I would like to be able to click on one field in a table, and retrieve
the data in another field. Here is the information:
The table is:
+----------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| Cust_Num | smallint(5) unsigned | NO | PRI | NULL | |
| Fname | varchar(25) | NO | | NULL | |
| Lname | varchar(25) | NO | | NULL | |
| Street | varchar(25) | NO | | NULL | |
| City | varchar(25) | NO | | NULL | |
| State | varchar(2) | NO | | NULL | |
| Zip | mediumint(9) | NO | | NULL | |
| Phone | int(10) | NO | | NULL | |
| Date | date | NO | | NULL | |
| Notes | text | YES | | NULL | |
| P1 | int(3) | YES | | NULL | |
| P2 | int(3) | YES | | NULL | |
| P3 | int(4) | YES | | NULL | |
+----------+----------------------+------+-----+---------+-------+
Click on Lname and retrieve the Cust_Num.
Here is the sql query that will be used:
$sql12 = 'SELECT Cust_Num, Fname, Lname, Street, City, State, Zip,
Phone, Notes FROM Customers WHERE Cust_Num = $_POST['Cust_Num'];
[I'm actually doing this w/ prepared statements]
$i = 0;
do
{
{
$vara2 = array(array($Cust_Num, $Fname,
$Lname, $Street, $City, $State, $Zip, $Phone, $Notes));
$vara2[$i][0] = $Cust_Num;
$vara2[$i][1] = $Fname;
$vara2[$i][2] = $Lname;
$vara2[$i][3] = $Street;
$vara2[$i][4] = $City;
$vara2[$i][5] = $State;
$vara2[$i][6] = $Zip;
$vara2[$i][7] = $Phone;
$vara2[$i][8] = $Notes;
$_SESSION['exe'] = 2;
?>
<tr>
<td class="cn"> <?php echo $vara2[$i][0]?> </td>
<td> <?php echo $vara2[$i][1]?> </td>
<tdclass="ln"> <?php echo $vara2[$i][2]?> </td>
<td> <?php echo $vara2[$i][3]?> </td>
<td> <?php echo $vara2[$i][4]?> </td>
<td> <?php echo $vara2[$i][5]?> </td>
<td> <?php echo $vara2[$i][6]?> </td>
<td> <?php echo $vara2[$i][7]?> </td>
<td class="first-col"><?php echo $vara2[$i][8] ?></td>
<?php
echo "</tr>\n";
$i = $i + 1;
}
} while (mysqli_stmt_fetch($stmt)); //end do-while
$imax = $i;
echo "</table>";
echo "</center>";
} // end count($errors_array)
Any ideas?
Eitan
I'm not sure what you are going to do with the customer number when you
get it since you are outside of php but here's one way of getting it on
the fly:
As you build your html table wtih php, assign an id to the name fields
and the custno fields, such as 'id=name1' id='name2', etc. and
'id=cust1', 'it=cust2' and so on.
On the name field also add an onclick=getCustNo($i) where $i has the
value of the id value. Then write a javascript function like:
function getCustNo(id)
{
var cno = "cust"+id;
var cname = "name"+id;
namefld = document.getElementById(cname).value;
custno = document.getElementById(cno).value;
alert("Customer "+namefld+ "has customer number "+custno);
return;
}
As I said - I don't know what you think you are going to do now but you
got it.
PS - I might have used ".value" when it should be ".innerHTML" in the js
code. You'll have to experiment.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php