Link to home
Start Free TrialLog in
Avatar of designersx
designersx

asked on

how i show the output according to the jpg's shown on selecting radiobutton and clicking save?

i am sending the 2 snapshots. i simply want that when the user check the first radio button and clicks the save button, then the output should be

rupinder
yogesh  (according to redio-btn.jpg)

output should be

yogesh
rupinder (according to redio-btn2.jpg)

by this i am setting the priority of the username to be displayed first.
redio-btn.jpg
redio-btn2.jpg
Avatar of Michael701
Michael701
Flag of United States of America image

Please post your code that has the html form and radio buttons. This way we can better answer your question by expanding on your starting point. (If you have no html code then that's also ok)

Next do you want this to use java script (no page refresh) or to call another php script and refresh the page?
Avatar of designersx
designersx

ASKER

i am sorry for my previous post that i was unable to make u understand. a little idea of what i want is changed.
 
respected sir, this is my HTML page. now what i want, the user will set the priority in the textboxes as 3,2,1 and click on the save button and according to that the entries will be saved in the database.

for easyness, you just display it after clicking the button. i can do it with database, you just tell me how to set the order of the items and display it on the front end.
<table width="60" border="1">
  <tr>
    <td><input name="t1" type="text" /></td>
    <td>name1</td>
  </tr>
  <tr>
    <td><input name="t2" type="text" /></td>
    <td>name2</td>
  </tr>
  <tr>
    <td><input name="t3" type="text" /></td>
    <td>name3</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input name="btn" type="button" value="save" /></td>
  </tr>
</table>

Open in new window

well assuming that the user will only enter 1, 2 or 3 then you could do this
unset($answers);
 
$answers[$_POST['t1']]='name1';
$answers[$_POST['t2']]='name2';
$answers[$_POST['t3']]='name3';
 
echo "First place:". $answers[1] ."<br />\n";
echo "Second place:". $answers[2] ."<br />\n";
echo "Third place:". $answers[3] ."<br />\n";

Open in new window

this sir actually i am doing with database and please see my code and run it. u will see when the user makes a new entry from database the textbox and name will be displayed.

after wards i will use select * from tablename order by fieldname . it will set the order of the items but how to pick the textbox values and store it in the field.
this is the main problem i am having.
<?php
$m=mysql_connect("localhost","root","");
$db=mysql_select_db('try');
 
$sql="select * from try order by id";
$query=mysql_query($sql);
while ($rec=mysql_fetch_array($query))
{
?>
<input type="text" name="<?php echo "text_".$rec['id']; ?>" />
<a href='1.php?id=<?php echo $rec['id'];?>'><?php echo $rec['name']; ?></a><br />
<br />
 
<?php
}
if(isset($_REQUEST['id'])&&$_REQUEST['id']!="")
{
	$sql1="select * from try where id =".$_REQUEST['id'];
	$query1=mysql_query($sql1);
	while ($rec1=mysql_fetch_array($query1))
	{
	echo $rec1['name'];
	}
}
?>
 
<form action="editquery.php" method="post" name="form">
<input type="button" value="save" />
</form>

Open in new window

am i right like this to pick the value of textbox

echo $_POST['"text_".$id'] ;

<?php
 
while ($rec=mysql_fetch_array($query))
{
$id="text_".$rec['id'];
?>
<input type="text" name="<?php echo $id; ?>"  />
<?php
}
?>
 
 
<form action="1.php" method="post" name="form">
<input type="submit" value="save" />
</form>
 
<?php
 
echo $_POST['"text_".$id'] or die(mysql_error(). "cant collet values");
?>

Open in new window

sir please see the attached code. i have modified the code with ur above code to swap the order according to the order written in the textbox.

please tell me how to line 23
<form name="form" action="2.php" method="post">
<?php
$m=mysql_connect("localhost","root","");
$db=mysql_select_db('try');
 
$sql="select * from try order by id";
$query=mysql_query($sql);
while ($rec=mysql_fetch_array($query))
{?>
	<input type="text" name="<?php echo "t".$rec['id']; ?>" value="<?php echo $rec['id'] ?>" />
	<a href="2.php?id=<?php echo $rec['id']; ?>"><?php echo $rec['name']; ?></a>
<br /><br />
 
<?php
}
 
if(isset($_POST['submit'])){
	$sql="select * from try order by id";
	$query=mysql_query($sql);
	while ($rec=mysql_fetch_array($query)){
		$name = $rec['name'];
	for($i=1;$i<=count($_POST);$i++){
		$answers[$_REQUEST["t".$i]]=
		$answers[$_REQUEST["t".$i]]=//here i need to pick the name according to the id??????????
		echo $answers[$i]."<br />\n";
		break;
	}	
}
}
?>
<input type="submit" name="submit" id="submit" value="save" />
</form>

Open in new window

hello sir where u gone?
sir see the lines 10 and 20 to 28 lines.i have complelty put my effort, please see where is the problem.

i am storing all the values in an array and exploding it later, please do let me know am i wrong?
<form name="form" action="2.php" method="post">
<?php
$m=mysql_connect("localhost","root","");
$db=mysql_select_db('try');
 
$sql="select * from try order by id";
$query=mysql_query($sql);
while ($rec=mysql_fetch_array($query))
{
	$a.= echo $rec['name']; // it will contain all the names order by id, later we will explode it and put it in the loop as it is.
	?>
		<input type="text" name="<?php echo "t".$rec['id']; ?>" value="<?php echo $rec['id'] ?>" />
		<a href="2.php?id=<?php echo $rec['id']; ?>"><?php echo $rec['name']; ?></a>
	<br /><br />
}	
	<?php
	
	$r= explode(" ",$a);
	
	if(isset($_POST['submit'])){
		for($i=1;$i<=count($_POST);$i++){
			$c[$_POST["t".$i]]=$r[$i];
		}	
 
		for($i=1;$i<=count($_POST);$i++){
			echo $c[$i];		// echo in this fashion $a[1], $a[2] and so on in the order wise
		}	
	}	
?>
<input type="submit" name="submit" id="submit" value="save" />
</form>

Open in new window

my latest code is this.
<form name="form" action="2.php" method="post">
<input type="submit" name="submit" id="submit" value="save" /><br />
 
<?php
$m=mysql_connect("localhost","root","");
$db=mysql_select_db('try');
 
$sql="select * from tablename1 order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query, MYSQL_BOTH))
{
?>
	<input type="text" name="<?php echo "t".$row['id']; ?>" />
	<a href="2.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a>
	<br /><br />
<?php
}
 
 
	if(isset($_POST['submit'])){
		for($i=1;$i<=count($_POST);$i++){
			$c[$_POST["t".$i]]=;// here i want to bring the name line wise so that they can be echoed ??
		}	
		
		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
		}	
	}

Open in new window

well since you didn't store the name,you'll have to read it from the database.
 if(isset($_POST['submit'])){
  for($i=1;$i<=count($_POST);$i++)
  {
    $sql_command = "select name from tablename1 where id=$i";
    $rs_person = mysql_query($sql_command);
    $person = mysql_fetch_assoc($rs_person);
    $c[$_POST["t".$i]]=$person['name'];
// here i want to bring the name line wise so that they can be echoed ??
                }    

Open in new window

respected Michael701,

u r like god to me,heads off to you buddy. my code works now. i spent 6 hours but was not able to do it 100%. haha


just little one thing i want to ask. now i am able to swap all the values as written by the user in the textbox. ok but can we save that order in the database?

yogesh
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America 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
i know this is the right query

$sql_command = "update tablename1 set `rank`=". $_POST["t".$i]." where id=$i";

but with this very different results i am getting. the whole program gets disturbed.

sit tell me 1 thing. like i am changing the order of id field and i have not made it auto number or primary key, do i need t make it?

see 25 and 26 line.
<form name="form" action="2.php" method="post">
<input type="submit" name="submit" id="submit" value="save" /><br />
 
<?php
$m=mysql_connect("localhost","root","");
$db=mysql_select_db('try');
 
$sql="select * from tablename1 order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query, MYSQL_BOTH))
{
	?>
		<input type="text" name="<?php echo "t".$row['id']; ?>" />
		<a href="2.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a>
	<br /><br />
	<?php
}
	if(isset($_POST['submit'])){
		  for($i=1;$i<=count($_POST);$i++){
			$sql_command = "select name from tablename1 where id=$i";
			$rs_person = mysql_query($sql_command);
			$person = mysql_fetch_assoc($rs_person);
			$c[$_POST["t".$i]]=$person['name'];
				
			$sql_command = "update tablename1 set `rank`=". $_POST["t".$i]." where id=$i";
    		$ok=mysql_query($sql_command);	
		  }
		  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
		  }	
	}
		
?>
 
</form>

Open in new window

i entered 4 3 2 1 in the textboxes as th order. then
output is right but why loop is moving like this and there is no updation in the table field.

update tablename1 set `order1`=4
where id=1update tablename1 set `order1`=4
where id=1update tablename1 set `order1`=3
where id=2update tablename1 set `order1`=4
where id=1update tablename1 set `order1`=3
where id=2update tablename1 set `order1`=2
where id=3update tablename1 set `order1`=4
where id=1update tablename1 set `order1`=3
where id=2update tablename1 set `order1`=2
where id=3update tablename1 set `order1`=1
where id=4

//echo count($_POST)-1;exit;
		  for($i=1;$i<=count($_POST)-1;$i++){
		  		echo $sql_command1 .= "update tablename1 set `order1`=". $_POST["t".$i]."<br>"." where id=$i";
    			$ok=mysql_query($sql_command1);	
		  }

Open in new window

the output is:)
its output is (when i enter 4 3 2  1 )
 
update tablename1 set `order1`=4 where id=1
 
update tablename1 set `order1`=4 where id=1
update tablename1 set `order1`=3 where id=2
 
update tablename1 set `order1`=4 where id=1
update tablename1 set `order1`=3 where id=2
update tablename1 set `order1`=2 where id=3
 
update tablename1 set `order1`=4 where id=1
update tablename1 set `order1`=3 where id=2
update tablename1 set `order1`=2 where id=3
update tablename1 set `order1`=1 where id=4

Open in new window

why do you have ."<br>". in the middle of you sql statement?

add an echo statement after the update
//echo count($_POST)-1;exit;
                  for($i=1;$i<=count($_POST)-1;$i++){
                                echo $sql_command1 .= "update tablename1 set `order1`=". $_POST["t".$i]." where id=$i";
                        $ok=mysql_query($sql_command1); 
                        echo $sql_command1."<br />\n";
                  }

Open in new window

oh sorry it was due to dot. ok ok
well that looks better, now is it updating the table?
yes sir it is really cool. sir if suppose a record is inserted and then deleted, then the id which is auto generated will be next ,then will it work?

like

id   name
1    yogesh
3    bansal
6    sona
yes, but rather than select by id, maybe you should sort by name on the initial form