Link to home
Start Free TrialLog in
Avatar of designersx
designersx

asked on

the code works when there are id's linewise means1,2,3,4 otherwise it gives error,please help me out.

this code works when i have the id's line wise, can u modify it please. whatever be the id ,it should flip the records accordingly.

in this code, i have records in the database. the user will set the order of the items to be displayed by entering in the textbox. please help me out, i am trying but not getting the result what i wanted.
<form name="form" action="2.php" method="post">
<input type="submit" name="submit" id="submit" value="save" /><br />
 
<?php
$con=odbc_connect('try','','');
 
$sql="select * from tablename1 order by id";
$query=odbc_exec($con, $sql);
while (odbc_fetch_row($query))
{	//echo "t".$query['id'];exit;
	echo $id="t".odbc_result($query,"id");
	//exit;
	?>
		<input type="text" name="<?php echo "t".odbc_result($query,"id"); ?>" />
		<a href="2.php?id=<?php echo $id=odbc_result($query,"id"); ?>"><?php echo $name=odbc_result($query,"name"); ?></a>
	<br /><br />
	<?php
}
 
	if(isset($_POST['submit'])){
		  for($i=1;$i<count($_POST);$i++){
		  	//echo $_POST["t".$i]."<br>";
			$con=odbc_connect('try','','');
			$sql_command = "select name from tablename1 where id=$i";
			$rs_person = odbc_exec($con, $sql_command);
			$person = odbc_fetch_row($rs_person);
			$c[$_POST["t".$i]]= odbc_result($rs_person,"name");
			//$c[$_POST["t".$i]]=$person['name'];
		  }
		  
		  
		  for($i=1;$i<count($_POST);$i++){
				echo $c[$i]."<br>";		// echo in this fashion $a[1], $a[2] and so on in the order wise
		  }
		  
		  //echo count($_POST)-1;exit;
		  for($i=1;$i<count($_POST);$i++){
		  		//echo $i."<br>";
				//echo $_POST["t".$i]."<br>";
				$con=odbc_connect('try','','');
				$sql_command1 = "update tablename1 set `order1`=". $_POST["t".$i]." where id=$i";
				$ok=odbc_exec($con, $sql_command1);
				//echo "<br><br>";
				echo "<br>";
		  }
	}
?>
</form>

Open in new window

Avatar of designersx
designersx

ASKER

here in this i need to apply the isset condition that if there is no record in the database, then it should not execute that statement.

i am trying but can u look at it. like this. see 24 and 39 line.
<form name="form" action="3.php" method="post">
<input type="submit" name="submit" id="submit" value="save" /><br />
 
<?php
$con=odbc_connect('db1','','');
 
$sql="select * from Table1 order by id";
$query=odbc_exec($con, $sql);
while (odbc_fetch_row($query))
{	//echo "t".$query['id'];exit;
	echo $id="t".odbc_result($query,"id");
	//exit;
	?>
		<input type="text" name="<?php echo "t".odbc_result($query,"id"); ?>" />
		<a href="2.php?id=<?php echo $id=odbc_result($query,"id"); ?>"><?php echo $name=odbc_result($query,"name"); ?></a>
	<br /><br />
	<?php
}
 
	if(isset($_POST['submit'])){
		  for($i=1;$i<count($_POST);$i++){
		  	//echo $_POST["t".$i]."<br>";
			$con=odbc_connect('db1','','');
			if(isset($_REQUEST["t".$i])){
				$sql_command = "select name from Table1 where id=".$i;
			}	
			$rs_person = odbc_exec($con, $sql_command);
			$person = odbc_fetch_row($rs_person);
			$c[$_POST["t".$i]]= odbc_result($rs_person,"name");
			//$c[$_POST["t".$i]]=$person['name'];
		  }
		  
		  for($i=1;$i<=count($_POST);$i++){
				echo $c[$i]."<br>";		
		  }
		  
		  for($i=1;$i<count($_POST);$i++){
				$con=odbc_connect('db1','','');
				if(isset($_REQUEST["t".$i])){
					echo $sql_command1 = "update Table1 set `order1`=". $_POST["t".$i]." where id=".$i;
				}
				$ok=odbc_exec($con, $sql_command1);
		}
	}
?>
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of agriesser
agriesser
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
please see

https://www.experts-exchange.com/questions/24365101/how-i-show-the-output-according-to-the-jpg's-shown-on-selecting-radiobutton-and-clicking-save.html


this was the question asked by me earlier but i closed it by mistake. i have done it 90% .

i am just setting the order of the items to be displayed on the front end and then save that order in the database in the field order1.

simply, i want to show that record first which has got priority 1 and so on.

ok , let me try ur code.

thanks
lots of error

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'id='., SQL state 37000 in SQLExecDirect in C:\wamp\www\fantaay\try\4.php on line 23

Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in C:\wamp\www\fantaay\try\4.php on line 24

Warning: odbc_result(): supplied argument is not a valid ODBC result resource in C:\wamp\www\fantaay\try\4.php on line 25

able to solve the code,don't take tension. thanks buddy for the pains u take for me.

thanks again.
OK, so, does it work now for you or is there anything left that doesn't work as expected?