Saturday, 7 September 2013

Unique Value For Each Button

Unique Value For Each Button

I have two php pages. The first page queries a database and places some
data into a form The second page, grabs the data submited from the
previous page and displays the data.
THE ISSUE: On the second page, the information is displayed in a table. At
the end of each row, there is a "information" button that allows the user
to click and see more details related to the data in that particular
column. For some reason, the information button for every record in the
table is holding the value of the first record returned in the database
query. In other words no matter what button I click on in the table, it
always relates to the first record returned in the query.
I'm hoping someone can help me find a solution to linking each
"information" button to each unique record. In other words If I click the
info button in row one, it will display the data for the record related to
row 1...etc. Here's my code.
PAGE 1
$query = mysql_query ("SELECT DISTINCT company_name FROM cust_data ORDER
by company_name ASC");
WHILE ($rows = @mysql_fetch_array($query))
{
If ($rows['company_name'] =="")
{echo '';}
else if ($rows['company_name']!=="")
{
echo '<form method="GET" action="customer_result_page.php">
<input type="hidden" value="'.$rows['company_name'].'"
name="company_name">
<input type="submit" value="'.$rows['company_name'].'"
name="'.$rows['company_name'].'" id="submit">
</form>';
}
}
}
PAGE 2 => GRABS THE DATA IN PAGE ONE AND PLACES IT IN A TABLE. WHEN THE
'INFO' BUTTON IS CLICKED, MORE INFORMATION IS DISPLAYED IN A JQUERY POPUP
echo'
<!DOCTYPE HTML>
<html>
<head>
<title>More Details</title>
</head>
<body>
<link rel="stylesheet" href="css/details_popup.css">
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.popupoverlay.js"></script>';
db_connect();
$company_name = $_GET['company_name'];
$query = @mysql_query ("SELECT * FROM cust_data WHERE
company_name = '$company_name' ");
WHILE ($rows = @mysql_fetch_array($query))
{
echo'
<tr>
<td><font size="4">'; echo $rows['account_number'];
echo'</font></td>
<td><font size="4">'; echo $rows['customer_first_name'];
echo '</font></td>
<td><font size="4">'; echo $rows['customer_last_name'];
echo '</font></td>
<td><font size="4">'; echo $rows['company_name']; echo
'</font></td>
<td><font size="4">'; echo $rows['cabinet_number'];
echo'</font></td>
<td><font size="4">'; echo $rows['key_tag_number'];
echo'</font></td>';
echo '<input type="hidden"
value="'.$rows['power_circuit'].'"
name="power_circuit">
<input type="hidden"
value="'.$rows['switch_and_port1'].'"
name="switch_and_port1">
<input type="hidden"
value="'.$rows['switch_and_port2'].'"
name="switch_and_port2">
<input type="hidden"
value="'.$rows['switch_and_port3'].'"
name="switch_and_port3">
<input type="hidden"
value="'.$rows['switch_and_port4'].'"
name="switch_and_port4">';
if ($rows['switch_and_port1'] =="")
{echo '';}
else if ($rows['switch_and_port1'] !== "")
{echo '<td><font size="4">'; echo '<input type =
"image" src= "images/view_details.png" height="16"
width="16" class="my_modal_open">', '</font></td>';}
echo '</tr>';
echo '<div class="well" style="display:none;margin:1em;"
id="my_modal">';
echo '<img src="images/hdc_logo_transparent.png"><br>';
echo '<div style="height:23px; width:100%;
background-color:black"><h4><font
color="#FFFFFF">','&nbsp; ', $rows['company_name'],
'</font></h4></div>';
echo '<p>';
echo '<br>';
echo '<img src="images/bulletpoint_orange.png">';
echo 'Power: &nbsp;&nbsp;&nbsp;&nbsp;',
$rows['power_circuit'];
echo '<br>';
echo'<img src="images/bulletpoint_orange.png">';
echo 'Sw/Po: &nbsp;&nbsp;&nbsp;&nbsp;',
$rows['switch_and_port1'];
if ($rows['switch_and_port2'] =="")
{echo '';}
else if ($rows['switch_and_port2'] !== "")
{
echo '<br>';
echo '<img src="images/bulletpoint_orange.png">';
echo 'Sw/Po: &nbsp;&nbsp;&nbsp;&nbsp;',
$rows['switch_and_port2'];
}
if ($rows['switch_and_port3'] =="")
{echo '';}
else if ($rows['switch_and_port3'] !== "")
{
echo '<br>';
echo '<img src="images/bulletpoint_orange.png">';
echo 'Sw/Po: &nbsp;&nbsp;&nbsp;&nbsp;',
$rows['switch_and_port3'];
}
if ($rows['switch_and_port4'] =="")
{echo '';}
else if ($rows['switch_and_port4'] !== "")
{
echo '<br>';
echo '<img src="images/bulletpoint_orange.png">';
echo 'Sw/Po: &nbsp;&nbsp;&nbsp;&nbsp;',
$rows['switch_and_port4'];
}
echo '</p>';
echo'</div></form>';
}
echo'
<script>
$(document).ready(function() {
$(".my_modal_open").click(function(){
$("#my_modal").popup({
"autoopen": true
});
});
});
</script>
</body>
</html>';

No comments:

Post a Comment