knight fyre
05-05-2009, 08:24 AM
What I'm trying to do is display all the appropriate records, the user will be able to use a checkbox to select the data records he wants submitted and then select the submit button.
So far it's been nothing but headache though. Am I approaching this issue in the right way?
The big problem I'm having is that there is no simple way to group the results from different forms. I was hoping the <fieldset> tag would solve my problem but it hasn't.
The approach I've taken is to send all the data via arrays and use a while function to pick the "select" array elements but so far it's not been working out.
Here is the code below.
<?php
/**
* @author Julian Josephs
* @copyright 2009
*/
$mysql = new mysqli('localhost', 'root', 'password', 'hoteldb') or die($mysql->error);
?>
<html>
<head></head>
<body>
<h2>Select the Guests that are Checking in</h2>
<?php
$guestObj = $mysql->query("SELECT * FROM admissiondata") or die ($mysql->error);
echo '<form method="POST" action="">';
$count = 0;
while( $guestRecord = $guestObj->fetch_object() )
{
echo '<fieldset>';
echo '<legend>' . $guestRecord->lastName . '</legend>';
echo '<input type="text" readonly="readonly" name="Reservation Number[]" value="' . $guestRecord->reservationNum . '" size="4" />';
echo '<input type="text" readonly="readonly" name="Guest Number[]" value="' . $guestRecord->guestNum . '" size="4" />';
echo '<input type="text" readonly="readonly" name="First Name[]" value="' . $guestRecord->firstName . '" size="10" />';
echo '<input type="text" readonly="readonly" name="Middle Initial[]" value="' . $guestRecord->mI . '" size="1" />';
echo '<input type="text" readonly="readonly" name="Last Name[]" value="' . $guestRecord->lastName . '" size="10" />';
echo '<input type="text" readonly="readonly" name="Credit Card[]" value="' . $guestRecord->creditCard . '" size="14" />';
echo '<input type="text" readonly="readonly" name="Cell Number[]" value="' . $guestRecord->cellNumber . '" size="7" />';
echo '<input type="text" readonly="readonly" name="Home Number[]" value="' . $guestRecord->homeNumber . '" size="7" />';
echo '<input type="text" readonly="readonly" name="Work Number[]" value="' . $guestRecord->workNumber . '" size="7" />';
echo '<input type="text" readonly="readonly" name="Num Of Days[]" value="' . $guestRecord->numOfDays . '" size="1" />';
echo '<input type="text" readonly="readonly" name="Charge[]" value="' . $guestRecord->charge . '" size="6" />';
echo '<input type="text" readonly="readonly" name="Cancelled[]" value="' . $guestRecord->canceled . '" size="6" />';
echo '<input type="text" readonly="readonly" name="Guest Room Num[]" value="' . $guestRecord->guestRoomNum . '" size="1"/>';
echo '<input type="checkbox" name="select[]" value="'. $count . '" />';
echo '</fieldset>';
echo '<br />';
$count++;
}
echo '<input type="submit" name="Add Records" value="Add Records" />';
echo '</form>';
?>
<?php
if(isset($_POST['Add_Records']))
{
echo '<pre>';
print_r($_POST);
echo '</pre>';
$ReservationNumber = array( $_POST['Reservation_Number'] );
$select = array( $_POST['select'] );
// PROBLEM HERE
$recNum = 0;
while( $recNum < 50 )
{
$seeker = 0;
while( $seeker < 50 )
{
if( $select[0][$recNum] == $seeker )
{
echo $ReservationNumber[0][$recNum];
echo '<br />';
echo $select[0][$recNum];
echo '<br />';
}
$seeker++;
}
$recNum++;
}
//echo '123<pre>';
//print_r($selected);
//echo '</pre>098';
}
?>
</body>
</html>
So far it's been nothing but headache though. Am I approaching this issue in the right way?
The big problem I'm having is that there is no simple way to group the results from different forms. I was hoping the <fieldset> tag would solve my problem but it hasn't.
The approach I've taken is to send all the data via arrays and use a while function to pick the "select" array elements but so far it's not been working out.
Here is the code below.
<?php
/**
* @author Julian Josephs
* @copyright 2009
*/
$mysql = new mysqli('localhost', 'root', 'password', 'hoteldb') or die($mysql->error);
?>
<html>
<head></head>
<body>
<h2>Select the Guests that are Checking in</h2>
<?php
$guestObj = $mysql->query("SELECT * FROM admissiondata") or die ($mysql->error);
echo '<form method="POST" action="">';
$count = 0;
while( $guestRecord = $guestObj->fetch_object() )
{
echo '<fieldset>';
echo '<legend>' . $guestRecord->lastName . '</legend>';
echo '<input type="text" readonly="readonly" name="Reservation Number[]" value="' . $guestRecord->reservationNum . '" size="4" />';
echo '<input type="text" readonly="readonly" name="Guest Number[]" value="' . $guestRecord->guestNum . '" size="4" />';
echo '<input type="text" readonly="readonly" name="First Name[]" value="' . $guestRecord->firstName . '" size="10" />';
echo '<input type="text" readonly="readonly" name="Middle Initial[]" value="' . $guestRecord->mI . '" size="1" />';
echo '<input type="text" readonly="readonly" name="Last Name[]" value="' . $guestRecord->lastName . '" size="10" />';
echo '<input type="text" readonly="readonly" name="Credit Card[]" value="' . $guestRecord->creditCard . '" size="14" />';
echo '<input type="text" readonly="readonly" name="Cell Number[]" value="' . $guestRecord->cellNumber . '" size="7" />';
echo '<input type="text" readonly="readonly" name="Home Number[]" value="' . $guestRecord->homeNumber . '" size="7" />';
echo '<input type="text" readonly="readonly" name="Work Number[]" value="' . $guestRecord->workNumber . '" size="7" />';
echo '<input type="text" readonly="readonly" name="Num Of Days[]" value="' . $guestRecord->numOfDays . '" size="1" />';
echo '<input type="text" readonly="readonly" name="Charge[]" value="' . $guestRecord->charge . '" size="6" />';
echo '<input type="text" readonly="readonly" name="Cancelled[]" value="' . $guestRecord->canceled . '" size="6" />';
echo '<input type="text" readonly="readonly" name="Guest Room Num[]" value="' . $guestRecord->guestRoomNum . '" size="1"/>';
echo '<input type="checkbox" name="select[]" value="'. $count . '" />';
echo '</fieldset>';
echo '<br />';
$count++;
}
echo '<input type="submit" name="Add Records" value="Add Records" />';
echo '</form>';
?>
<?php
if(isset($_POST['Add_Records']))
{
echo '<pre>';
print_r($_POST);
echo '</pre>';
$ReservationNumber = array( $_POST['Reservation_Number'] );
$select = array( $_POST['select'] );
// PROBLEM HERE
$recNum = 0;
while( $recNum < 50 )
{
$seeker = 0;
while( $seeker < 50 )
{
if( $select[0][$recNum] == $seeker )
{
echo $ReservationNumber[0][$recNum];
echo '<br />';
echo $select[0][$recNum];
echo '<br />';
}
$seeker++;
}
$recNum++;
}
//echo '123<pre>';
//print_r($selected);
//echo '</pre>098';
}
?>
</body>
</html>