Jump to content

Recommended Posts

I have a string that contain the following,

Room type, beds in room, Total Rooms.And the string outputted, can look like this.

Single Room, 2, 5;

Twin Room, 4, 2;

3 Bedroom, 2, 5;

 

Now I can explode this string to get the individual stings. I then display it in a table for people to see and to fill in fields next to it, to allow them to select the amount of room with the amount of adults and children they want in this room/s.

 

But how will I do the validationnin these string fields to make sure they dont select more people that a room or total room can have?

 

PLEASE CAN SOMEONE HELP ME WITH THIS!???

You could set your form fields (dropdowns? textfields?) to be something like 1_0, 1_1, 1_2, which would be the room (first part) and the part of the array (second part). Then, in your validation code, you could say "for size of the array for the first string, get the submitted value key 0, key 1, key 2, etc and compare them with my array key 0, key 1, key 2, etc"

 

 

Hi JD,

 

I am using the following script to display the exploded strings in a table:

while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
//////////////////////////////////////
$reg_name = $row['est_name'];
$inputid=$row['update_id'];
$fullrow = $row['accom_type'];
$pp_pr = $row['pp_pr'];
$fieldid = '$inputid-units';
$maxunits = $row['max'];
echo "<tr><td>";
echo $row['accom_type'].' - '.$row['max'].' units - '.$row['pax'].' beds per unit';
echo "</td><td>";
echo "<input id='$inputid-units' class='TextField' name='fields[$inputid][units]' type='text' size='3' value=0 maxlength='3'>";
echo "</td><td>";
echo "<input id='$inputid-adults' class='TextField' name='fields[$inputid][adults]' type='text' size='3' value=0 maxlength='3'>";
echo "</td><td>";
echo "<input id='$inputid-children' class='TextField' name='fields[$inputid][children]' type='text' size='3' value=0 maxlength='3'>";
echo "</td><td>";
echo "<input id='$inputid-infants' class='TextField' name='fields[$inputid][infants]' type='text' size='3' value=0 maxlength='3'>";
echo "</td></tr>";
echo "<input type='hidden' id='$inputid-accom_type' name='fields[$inputid][accom_type]' value='$fullrow'>";
echo "<input type='hidden' id='$inputid-pp_pr' name='fields[$inputid][pp_pr]' value='$pp_pr'>";

/////////////////////////////////////////

}

 

This is working fine for the display. Then I was thinking of using livevalidation to do the validation like so:

while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
//////////////////////////////////////
$reg_name = $row['est_name'];
$inputid=$row['update_id'];
$fullrow = $row['accom_type'];
$pp_pr = $row['pp_pr'];
$fieldid = '$inputid-units';
$maxunits = $row['max'];
echo "<tr><td>";
echo $row['accom_type'].' - '.$row['max'].' units - '.$row['pax'].' beds per unit';
echo "</td><td>";
echo "<input id='$inputid-units' class='TextField' name='fields[$inputid][units]' type='text' size='3' value=0 maxlength='3'>
<script type='text/javascript'>
var $fieldid = new LiveValidation('$fieldid');
$fieldid.add( Validate.Numericality, { minimum: 0, maximum: $maxunits, onlyInteger: true } );
</script>
";
echo "</td><td>";
echo "<input id='$inputid-adults' class='TextField' name='fields[$inputid][adults]' type='text' size='3' value=0 maxlength='3'>";
echo "</td><td>";
echo "<input id='$inputid-children' class='TextField' name='fields[$inputid][children]' type='text' size='3' value=0 maxlength='3'>";
echo "</td><td>";
echo "<input id='$inputid-infants' class='TextField' name='fields[$inputid][infants]' type='text' size='3' value=0 maxlength='3'>";
echo "</td></tr>";
echo "<input type='hidden' id='$inputid-accom_type' name='fields[$inputid][accom_type]' value='$fullrow'>";
echo "<input type='hidden' id='$inputid-pp_pr' name='fields[$inputid][pp_pr]' value='$pp_pr'>";

/////////////////////////////////////////

}

 

But it does not work????

 

Any idea why????

 

Thanks

i really don't have a clue what you're doing here...

 

so, you're starting with something like: 'Single Room, 2, 5', which is coming from where, the db?

 

then, you want to break that into three (3) parts, ie.

$str = 'Single Room, 2, 5';
$arr = explode(", ", $str);

 

now you have an array ($arr) to do with what you please.

 

i'm lost after that .. and why are your input values set to 0?

The default value of 0 is because there can be up to 18 dif rooms and will help with validation to test that the max value is between 0 and the given max value.

 

I get the string from a DB....

 

AAAAAAAarrrrrrrrrrrrrrrghhhhhhhhh! This section is driving me CRAZY!!!!

If you're grabbing your rows from a database, you don't need to put them into an array...you can just reference them from your query.

 

But lets clean up your code so it's a bit easier to read, and then I'll need a little explanation on some parts:

 


<?
while($row = mysql_fetch_array( $result )) {
   // Print out the contents of each row into a table
//////////////////////////////////////
$reg_name = $row['est_name'];
$inputid=$row['update_id'];
$fullrow = $row['accom_type'];
$fieldid = '$inputid-units';
$maxunits = $row['max'];
echo '<tr>
			<td>'.$row['accom_type'].' - '.$row['max'].' units - '.$row['pax'].' beds per unit</td>
			<td><input id="'.$inputid-units.'" class="TextField" name="'.fields[$inputid][units].'" type="text" size="3" value="0" maxlength="3"></td>
			<td><input id="'.$inputid-adults.'" class="TextField" name="'.fields[$inputid][adults].'" type="text" size="3" value="0" maxlength="3"></td>
			<td><input id="'.$inputid-children.'" class="TextField" name="'.fields[$inputid][children].'" type="text" size="3" value="0" maxlength="3"></td>
			<td><input id="'.$inputid-infants.'" class="TextField" name="'.fields[$inputid][infants].'" type="text" size="3" value="0" maxlength="3"></td>
	</tr>
	<input type="hidden" id="'.$inputid-accom_type.'" name="'.fields[$inputid][accom_type].'" value="'.$fullrow.'">
	<input type="hidden" id="'.$inputid-pp_pr.'" name="'.fields[$inputid][pp_pr].'" value="'.$row['pp_pr'].'">';

/////////////////////////////////////////

}
?>

 

I'm not sure about these parts:

 

$reg_name = $row['est_name'];

$inputid=$row['update_id'];

$fullrow = $row['accom_type'];

$fieldid = '$inputid-units';

$maxunits = $row['max'];

 

They don't seem to be referenced in any of your code from above. Also, when getting the ID and name for your fields, why are you doing fields[$inputid][units], etc, instead of just doing $row['units']? I'm not sure how others feel, but I stopped declaring variables for SQL returns a long time ago and just reference them directly in the code, so

 

$ID = mysql_result($result, $i, "ID");

echo $ID

 

for me just became

 

echo mysql_result($result, $i, "ID");

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.