how to get 2 variabilitys

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
the_power
Forum Newbie
Posts: 10
Joined: Tue Dec 04, 2007 2:34 pm

how to get 2 variabilitys

Post 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" .....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you looked at the output?
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: how to get 2 variabilitys

Post 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.
the_power
Forum Newbie
Posts: 10
Joined: Tue Dec 04, 2007 2:34 pm

I'm afraid this is not a code.

Post 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
Post Reply