 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 21st, 2004, 03:05 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Isolation of results
I am wondering if anyone can tell me how to isolated a single result from a multiple result query?
Example I enter my identification number, and the query returns three results of meetings I have been involved in. I need to select a single result from that to see the action from that meeting. The code I have written follows:
search1.php
Code:
<form action="/consult.php" method="get" name="Form2">
<table width ="100%" border = "1">
<tr>
<td>SID</td>
<td>Name</td>
<td>Subject</td>
<td>Start Date</td>
<td>Lecturer Name</td>
<td> </td>
</tr>
<?php do{?>
<tr>
<td><input type="text" name="StudentID" value="<?php echo $row_Recordset1['StudentID']; ?>"></td>
<td><input type="text" name="studentName" value="<?php echo $row_Recordset1['studentName']; ?>"></td>
<td><input type="text" name="Subject" value="<?php echo $row_Recordset1['subject']; ?>"></td>
<td><input type="text" name="dateStarted" value="<?php echo $row_Recordset1['dateStarted']; ?>"></td>
<td><input type="text" name="LectName" value="<?php echo $row_Recordset1['LectName']; ?>"></td>
<td><input type="submit" value="Select Entry" ></td>
</tr>
<?php }while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
</table>
</form>
The above code shows the select results, and the button to select which result I am looking for.
The below code is taken from consult.php which displays the results of the selected query
Code:
<?php
//collect $_POST data
$SID = $_POST['StudentID'];
$Name = $_POST['studentName'];
$Subj = $_POST['Subject'];
$dateStart = $_POST['dateStarted'];
$LectName = $_POST['LectName'];
//The Query to be executed
$SQL = "SELECT a.details";
$SQL .= " FROM ACTION a INNER JOIN CONSULTATION c ON a.ConsultationID = c.ConsultID";
$SQL .= " INNER JOIN ISSUE i ON c.IssueID = i.IssueID";
$SQL .= " WHERE i.subject = \"$Subj\";";
$consultRS = mysql_query($SQL, $APUProjConn) or die(mysql_error());
$row_consultRS = mysql_fetch_assoc($consultRS);
$totalRows_consultRS = mysql_num_rows($consultRS);
echo ($subj);
//Asign $action to the result
$Action = $row_consultRS['details'];
?>
<table width="100%" >
<tr>
<td colspan="2" ><div align="center"><?php echo($Subj);?></div></td>
</tr>
<tr>
<td width="50%"><div align="center">Date</div></td>
<td width="50%"><div align="center">Lecturer</div></td>
</tr>
<tr>
<td width="50%"><div align="center"><?php echo($dateStart);?></div></td>
<td width="50%"><div align="center"><?php echo($LectName);?></div></td>
</tr>
<tr>
<td colspan="2"><div align="center">Action</div></td>
</tr>
<tr>
<td colspan="2"><div align="center"><?php echo($Action);?></div></td>
</tr>
</table>
The code that is displayed, always displays the details of the bottom meeting, no matter which button I press. How do I isolated say row 2, instead of the last row?
Many thanks.
---
David Thorne, Student
UK
__________________
---
David Thorne, Student
UK
|
|

February 21st, 2004, 03:37 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
I may be wrong, but it looks like you are using the wrong method in your form.
You use <form method="get">
and then expect to get the results with $_POST[]...
Try using method="POST". Please tell me if this changes anything.
I hope I am right in solving your problem,
----------
---Snib---
----------
|
|

February 21st, 2004, 04:05 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
just tried that, no. Thanks for the thought though.
I am at a loss on this one.
---
David Thorne, Student
UK
|
|

February 22nd, 2004, 11:42 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have discovered how to do it with $_GET but I would prefer to use $_POST as it doesn't require the use of the address bar (So no one "knows" whats going on) any ideas? code as follows:
search1.php
Code:
<form method="get" name="Form2">
<table width ="100%" border = "1">
<tr>
<td>SID</td>
<td>Name</td>
<td>Subject</td>
<td>Start Date</td>
<td>Lecturer Name</td>
<td> </td>
<td> </td>
</tr>
<?php
$index=0;
do
{?>
<tr>
<td><input type="text" name="StudentID" value="<?php echo (mysql_result($Recordset1,$index,"studentID")); ?>"></td>
<td><input type="text" name="studentName" value="<?php echo (mysql_result($Recordset1,$index,"studentName")); ?>"></td>
<td><input type="text" name="Subject" value="<?php echo (mysql_result($Recordset1,$index,"subject")); ?>"></td>
<td><input type="text" name="dateStarted" width="250" value="<?php $myDate = date('H:i:s, d/m/y.',mysql_result($Recordset1,$index,"dateStarted")); echo ($myDate);?>"></td>
<td><input type="text" name="LectName" value="<?php echo (mysql_result($Recordset1,$index,"LectName")); ?>"></td>
<td><input type="text" name="indexVal" value="<?php echo ($index); ?>"></td>
<td><a href="<?php echo("/consult.php?Subject=".mysql_result($Recordset1,$index,"subject")."&StudentID=".mysql_result($Recordset1,$index,"studentID")."&studentName=".mysql_result($Recordset1,$index,"studentName")."&dateStarted=".mysql_result($Recordset1,$index,"dateStarted")."&LectName=".mysql_result($Recordset1,$index,"LectName"));?>">Link here</a></td>
</tr>
<?php $index++;
}while(@ $index< @$totalRows_Recordset1);?>
</table>
</form>
consult.php
Code:
<?php
//collect $_POST data
$SID = $_GET['StudentID'];
$Name = $_GET['studentName'];
$Subj = $_GET['Subject'];
$dateStart = $_GET['dateStarted'];
$LectName = $_GET['LectName'];
Thanks in advance
---
David Thorne, Student
UK
|
|

February 22nd, 2004, 11:17 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
Try placing the form tags inside the do while loop.
<?php do{?>
<form action="/consult.php" method="get" name="Form2">
<tr>
<td><input type="text" name="StudentID" value="<?php echo $row_Recordset1['StudentID']; ?>"></td>
<td><input type="text" name="studentName" value="<?php echo $row_Recordset1['studentName']; ?>"></td>
<td><input type="text" name="Subject" value="<?php echo $row_Recordset1['subject']; ?>"></td>
<td><input type="text" name="dateStarted" value="<?php echo $row_Recordset1['dateStarted']; ?>"></td>
<td><input type="text" name="LectName" value="<?php echo $row_Recordset1['LectName']; ?>"></td>
<td><input type="submit" value="Select Entry" ></td>
</tr>
</form>
<?php }while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
At the moment what is happening is you are creating three sets of text boxes (student id, student name subject etc) all with the same name and so when the next page tries to get the value it only gets the last set
Hope this helps
Chris
|
|

February 23rd, 2004, 09:32 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Chris, Sorted
---
David Thorne, Student
UK
|
|
 |