Page 1 of 1

how to get 2 variabilitys

Posted: Wed Dec 05, 2007 8:13 pm
by the_power

Code: Select all

<form method="post" action="moves.php">
<?php
      $sql = mysql_query("SELECT * FROM `route` WHERE `office`='".$users['office']."' and `date`='".date("d.m.Y")."' ORDER BY `id` DESC;");
	while($row=mysql_fetch_array($sql)){


?>

      	<tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
		<td width="15%"><center><?php print (stripslashes(htmlspecialchars($row['name']))); ?></center></td>
		<td width="18%"><center><?php print (stripslashes(htmlspecialchars($row['address']))); ?></center></td>
		<td width="14%"><center><?php print (stripslashes(htmlspecialchars($row['gsm']))); ?></center></td>
		<td width="15%"><center><?php print (stripslashes(htmlspecialchars($row['chas']))); ?></center></td>
            <td width="15%"><center><?php print (stripslashes(htmlspecialchars($row['shipment']))); ?></center></td>
<td>
<center><select name="zone[]" value="<?=strval( $row['id'] );?>">
<option select>- - Zones - -</option>
<?
$val=1;
$sqls = mysql_query("SELECT `zones` FROM `office` where `officename`='".$users['office']."' ORDER BY `id` DESC;");
while ($val=mysql_fetch_array($sqls)) {
$zon=$val['zones'];
}
for ($i=1;$i<$zon+1; $i++)
{
?>
<option value="<?php echo "$i"; ?>">Zone: <?php echo "$i"; ?></option>
<?
}
?>
</select></center>
<?	
}
?>
in moves.php i have this:

Code: Select all

foreach($_POST['zone'] as $zones)
{
if ( $zones > "0" ) {
echo "$zones<br>";
}
}
How i get "row id", "$zones" and post in moves.php? For "$zones" i know, but "row id" .....

Posted: Wed Dec 05, 2007 9:17 pm
by feyd
Have you looked at the output?

Re: how to get 2 variabilitys

Posted: Wed Dec 05, 2007 9:30 pm
by Chalks
the_power wrote:How i get "row id", "$zones" and post in moves.php? For "$zones" i know, but "row id" .....
I would change this:

Code: Select all

<select name="zone[]" value="<?=strval( $row['id'] );?>">
<option select>- - Zones - -</option>
<?
$val=1;
$sqls = mysql_query("SELECT `zones` FROM `office` where `officename`='".$users['office']."' ORDER BY `id` DESC;");

while ($val=mysql_fetch_array($sqls)) {
  $zon=$val['zones'];
}

for ($i=1;$i<$zon+1; $i++) {
?>
  <option value="<?php echo "$i"; ?>">Zone: <?php echo "$i"; ?></option>
<?php  //don't use short tags here
}
?>

</select></center>
to

Code: Select all

<select name="zoner">
<option select>- - Zones - -</option>
<?
$val=1;
$sqls = mysql_query("SELECT `zones`, 'id' FROM `office` where `officename`='".$users['office']."' ORDER BY `id` DESC;");

while ($val=mysql_fetch_array($sqls)) {
  echo "<option value="$val[0]:$val[1]">Zone: $val[0]</option>";
}
?>

</select></center>
and change moves.php to:

Code: Select all

if(isset($_POST['zoner']))
{
  list($zone, $id) = explode(":", $_POST['zoner']);
  echo "At row $id, we have zone $zone";
}

I think that does what you're looking for. Your code was a tad confusing in several places... why did you have a foreach() in moves.php, and what's the point of the long value for "<select name="zone[]" value="<?=strval( $row['id'] );?>">"? Also, the spacing in your code was, well... almost nonexistent. Try to indent loops, and pretty much anything else. It improves readability quite a bit.

I'm afraid this is not a code.

Posted: Thu Dec 06, 2007 3:00 am
by the_power
This code don't show anythings:

Code: Select all

while ($val=mysql_fetch_array($sqls)) {
  echo "<option value=\"$val[0]:$val[1]\">Zone: $val[0]</option>";
}
?>
In my db i have numer - example 8 and i want when i select this numer with sql request show Zones from 1 to 8 in drop-down menu.And i want to choose one, two or more zone's rows and post "row id" and chosen zone on this row in move.php