How to get the value in a row

i have query the below


$open=mssql_query("Select * from tblTicket inner join tblAssign on 
tblTicket.TickNo=tblAssign.TicketNo where tblAssign.AssignTo='$_SESSION[username]'");

<?php

while($row=mssql_fetch_array($open))
{
?>
<tr>
	<td><?php echo $row['TickNo']?></td>
	<td><?php echo $row['UserName']?></td>
	<td><?php echo $row['DateCreate']?> </td>
	<td><?php echo $row['TimeCreate']?> </td>
	<td><?php echo $row['Category']." (".$row['Subcat'].")"?></td>
<?php
}
<?

is there a way that can i extract the PK of the 1st row or the 2nd row.
Thanks…

There sure is!


$IDs = array();
while($row=mssql_fetch_array($open))
{
    $IDs[] = $row['ID']; //replace the array key with whatever the name of the ID column is
    echo '<tr>';
    echo "<td>{$row['TickNo']}</td>";
    echo "<td>{$row['UserName']}</td>";
    echo "<td>{$row['DateCreate']}</td>";
    echo "<td>{$row['TimeCreate']}</td>";
    echo "<td>{$row['Category']} ({$row['Subcat']})</td>";
    echo '</tr>';
}
if(empty($IDs)){
    echo 'No Rows Found';
}else{
    echo 'First ID: ' . $IDs[0];
}

Thanks for the reply…

your query is execute right.

but i want is to pass the value of TickNo if i choose below option.


 function OnChange(dropdown){
    var myindex = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
    var baseURL = 'Transfer.php'
    top.location.href = baseURL;
	
}

 echo "<select name='selectBox' idno='$row[TickNo]' onchange='OnChange(this.form.selectBox);'>";
    echo "<option selected>Please Select";
	while($row3=mssql_fetch_assoc($Assign)){
	echo"<option name=option value=id{'$row[TickNo]}'>$row3[MISPIC]</option>";
	}echo "</select>";


Appriate more help.
Thanks…

I’m afraid you’re going to have to explain what you want a little further, I’m struggling to understand what you’re after.

sorry for the confusion…

i have attach the picture for the script below.


<?php

session_start();
include_once("conn.php");
if(isset( $_SESSION['username']));
echo "Welcome $_SESSION[username]";

$open=mssql_query("Select * from tblTicket inner join tblAssign on 
tblTicket.TickNo=tblAssign.TicketNo where tblAssign.AssignTo='$_SESSION[username]'");
?>

<html>
<head>
	<title>Tikcet Support</title>
<script type="text/javascript">
 function OnChange(dropdown){
    var myindex = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
    var baseURL = 'Transfer.php?$IDs[0]='
    top.location.href = baseURL;
	
}

</script>
</head>
<body>
<table border='1'>
<tr>
	<td>Ticket</td>
	<td>User Name</td>
	<td>Date</td>
	<td>Time</td>
	<td>Category</td>
	<td>Transfer JO</td>
</tr>

<?php
$IDs = array();
while($row=mssql_fetch_array($open))
{
$Assign=mssql_query("Select * from MISPIC");
echo "<form name='test' method='post'>";
?>
<tr>
	<?php $IDs[] = $row['TickNo']; ?>
	<td><?php echo "<a href='Ticketmanage.php?id={$row['TickNo']}'>".$row['TickNo']."</a>"?></td>
	<td><?php echo $row['UserName']?></td>
	<td><?php echo $row['DateCreate']?> </td>
	<td><?php echo $row['TimeCreate']?> </td>
	<td><?php echo $row['Category']." (".$row['Subcat'].")"?></td>
	<td>
	<?php

    echo "<select name='selectBox' idno='$row[TickNo]' onchange='OnChange(this.form.selectBox);'>";
    echo "<option selected>Please Select";
	while($row3=mssql_fetch_assoc($Assign)){
	echo"<option name=option value=id{'$row[TickNo]}'>$row3[MISPIC]</option>";
	}echo "</select>";

	?>
	</td>
</tr>
<?php
echo "</form>";
}
?>

</table>
<a href='Support.php'>Back</a>
</body>
</html>

Thanks for the help.

I see what you mean now.

I’ve suggested a rewrite below, which removes a few errors and structures the page in a more logical way. One thing I wasn’t sure of, whilst it isn’t any of my business, is the usability of a form which redirects to a processing page when a select option is changed - what if the user clicked it by accident?

Anyway, here’s a version without the automatic direction but with an update button as an alternative:

<?php 
session_start();
include_once("conn.php");
if(isset($_SESSION['username'])){
	$Tickets = array();
	$AssignOptions = array();
	$selectTicketsQuery = mssql_query("SELECT * FROM tblTicket INNER JOIN tblAssign ON tblTicket.TickNo=tblAssign.TicketNo WHERE tblAssign.AssignTo='{$_SESSION['username']}'");
	while($Ticket = mssql_fetch_array($selectTicketsQuery)){
		$Tickets[] = $Ticket;
	}
	$Assign = mssql_query("Select * from MISPIC");
	while($AssignOption = mssql_fetch_assoc($Assign)){
		$AssignOptions[] = $AssignOption;
	}
	?>
	<html>
		<head>
			<title>Ticket Support</title>
		</head>
		<body>
			<p>Welcome <?php echo $_SESSION['username']; ?>!</p>
			<table border='1'>
				<tr>
					<th>Ticket</th>
					<th>User Name</th>
					<th>Date</th>
					<th>Time</th>
					<th>Category</th>
					<th>Transfer JO</th>
				</tr>
				<?php
					foreach($Tickets as $Ticket){
						echo '<tr>';
							echo '<td><a href="Ticketmanage.php?id=', $Ticket['TickNo'], '">', $Ticket['TickNo'], '</a></td>';
							echo '<td>', $Ticket['UserName'], '</td>';
							echo '<td>', $Ticket['DateCreate'], '</td>';
							echo '<td>', $Ticket['TimeCreate'], '</td>';
							echo '<td>', $Ticket['Category'], ' (', $Ticket['Subcat'], ')</td>';
							echo '<td>';
								echo '<form action="Transfer.php" method="get">';
								echo '<input type="hidden" name="TicketNo" value="', $Ticket['TickNo'], '" />';
								echo '<select name="TransferOption">';
									echo '<option value="0">Please Select</option>';
									foreach($TransferOptions as $TransferOption){
										echo '<option value="', $TransferOption['MISPIC'], '">', $TransferOption['MISPIC'], '</option>';
									}
								echo '</select>';
								echo '<input type="submit" value="Update" />';
								echo '</form>';
							echo '</td>';
						echo '</tr>';
					}
				?>
			</table>
			<p><a href='Support.php'>Back</a></p>
		</body>
	</html><?
}else{ //not logged in
	header('location: login.php');
}

If you’re sure that you want the form to automatically submit:

<?php 
session_start();
include_once("conn.php");
if(isset($_SESSION['username'])){
	$Tickets = array();
	$AssignOptions = array();
	$selectTicketsQuery = mssql_query("SELECT * FROM tblTicket INNER JOIN tblAssign ON tblTicket.TickNo=tblAssign.TicketNo WHERE tblAssign.AssignTo='{$_SESSION['username']}'");
	while($Ticket = mssql_fetch_array($selectTicketsQuery)){
		$Tickets[] = $Ticket;
	}
	$Assign = mssql_query("Select * from MISPIC");
	while($AssignOption = mssql_fetch_assoc($Assign)){
		$AssignOptions[] = $AssignOption;
	}
	?>
	<html>
		<head>
			<title>Ticket Support</title>
		</head>
		<body>
			<p>Welcome <?php echo $_SESSION['username']; ?>!</p>
			<table border='1'>
				<tr>
					<th>Ticket</th>
					<th>User Name</th>
					<th>Date</th>
					<th>Time</th>
					<th>Category</th>
					<th>Transfer JO</th>
				</tr>
				<?php
					foreach($Tickets as $Ticket){
						echo '<tr>';
							echo '<td><a href="Ticketmanage.php?id=', $Ticket['TickNo'], '">', $Ticket['TickNo'], '</a></td>';
							echo '<td>', $Ticket['UserName'], '</td>';
							echo '<td>', $Ticket['DateCreate'], '</td>';
							echo '<td>', $Ticket['TimeCreate'], '</td>';
							echo '<td>', $Ticket['Category'], ' (', $Ticket['Subcat'], ')</td>';
							echo '<td>';
								echo '<form action="Transfer.php" method="get">';
								echo '<input type="hidden" name="TicketNo" value="', $Ticket['TickNo'], '" />';
								echo '<select name="TransferOption" onChange="form.submit()">';
									echo '<option value="0">Please Select</option>';
									foreach($TransferOptions as $TransferOption){
										echo '<option value="', $TransferOption['MISPIC'], '">', $TransferOption['MISPIC'], '</option>';
									}
								echo '</select>';
								echo '</form>';
							echo '</td>';
						echo '</tr>';
					}
				?>
			</table>
			<p><a href='Support.php'>Back</a></p>
		</body>
	</html><?
}else{ //not logged in
	header('location: login.php');
}

It should work fine, and when the form is submitted via your chosen method, it will go to Transfer.php with the ticket number set as $_POST[‘TicketNo’] and the dropdown selection set as $_POST[‘TransferOption’]. $_GET shouldn’t really be used for pages which require modification processing, only selection processing. That’s upto you though, you can change it by changing the form method.

Thanks for the reply…

Greatly appreciate it…

but how can i populate the for each that in the DB…



 echo '<form action="Transfer.php" method="get">';
                                echo '<input type="hidden" name="TicketNo" value="', $Ticket['TickNo'], '" />';
                                echo '<select name="TransferOption" onChange="form.submit()">';
                                    echo '<option value="0">Please Select</option>';
                                    foreach($TransferOptions as $TransferOption){
                                        echo '<option value="', $TransferOption['MISPIC'], '">', $TransferOption['MISPIC'], '</option>';
                                    }
                                echo '</select>';

Again Thanks…it work like a charm…