Hello i want to select a row from this search and paste it to the next page do i need anymore code in each row, cus all it shows is a textbox next to each row. Ive got all connections, the search all works and its in a form i would be grateful for any help. thanks guys

echo "<tr>".
'<td style="color: black;"><input type="checkbox" name="hello[]" value="'.$a_row.'"></td>'.
"<td style=\"color:Black\">".$a_row."</td>".
"<td style=\"color:Black\">".$a_row."</td>".
"<td style=\"color:Black\">".$a_row."</td>".

In the next page, if you do, print_r($_POST); you will see ONLY the list of checkboxes which were checked..

In the next page, if you do, print_r($_POST); you will see ONLY the list of checkboxes which were checked..

hello naveen that displayed;

Array ( [0] => 9 [1] => 14 )

i want the chosen rows to be displayed but it only displays that why is this never seen that before cheers

You mean, you want to see all the other details like

<td style=\"color:Black\">".$a_row."</td>".
"<td style=\"color:Black\">".$a_row."</td>".
"<td style=\"color:Black\">".$a_row."</td>".

? You cant. If you want all these details to be passed onto the next page, have textboxes assign these values to the textboxes and then you can get these values in the next page. Or, use session.

hello naveen i just want to display them like you just said, can you give me an example of how to use the session because i dont want to use textboxes to display the data

Well, if you wish to use sessions, its going to be a lil tedious because, say for example, there are 10 checkboxes and the user selects 5. You need to have an array of session variables and get only the selected index of the checkbox. Thats going to be very difficult !
But you can try this alternative. Instead of,

<input type="checkbox" name="hello[]" value="'.$a_row.'">

pass $row, $row and $row as the value.

$value = $row['date']. ";".$row['school'].";".$row['people'];
<input type="checkbox" name="hello[]" value=".$value.">

So, when a checkbox is checked, all these values are passed onto the next page as the checkbox value.

Thank u naveen for your quick reponse ill try it cheers, but dont i need ID because its in the database..

What are you doing with the ID ? Are you using it to do anything important ? Like updating/inserting any value to a table ? If so, you need ID field. Umm.. Hey, why not do it this way. ID represents a row in the table. For example, If ID = 1, all the other details, $a_row, $a_row and $a_row will have the relevant value. Why not query the table and get the data when the user submits the form ?
Ie., from your code, you have passed 2 values to the next page.

Array ( [0] => 9 [1] => 14 )

Query the table and get the rows where ID = 9 and 14 respectively.

<?php
foreach($_POST['checkboxname'] as $value){
$query = "select * from table where id='$value'";
//execute the query and get the rows and print it..
}

hello naveen thats what i need foreach because id represents each row in the database, because once the user selects the checkbox it sumits it 2nextpage then inserts to database like you said.. You no the code you gave me above does that go on the checkbox page or the page when the row is submitted thanks

I dont understand.. You already have a record in the table and you want to insert another record for the same ID ? Can you explain in detail what exactly are you trying to do ?

hello already have that record in the table but once the user selects it, its gone be sent to another table within the database.

Then query the table with the ID's passed.. Get the row and insert it to another table.

What are you doing with the ID ? Are you using it to do anything important ? Like updating/inserting any value to a table ? If so, you need ID field. Umm.. Hey, why not do it this way. ID represents a row in the table. For example, If ID = 1, all the other details, $a_row, $a_row and $a_row will have the relevant value. Why not query the table and get the data when the user submits the form ?
Ie., from your code, you have passed 2 values to the next page.

Query the table and get the rows where ID = 9 and 14 respectively.

<?php
foreach($_POST['checkboxname'] as $value){
$query = "select * from table where id='$value'";
//execute the query and get the rows and print it..
}

Hello naveen so i put this code above on the next page when the user clicks on submit?
foreach($_POST as $value){
and in checkbox name i put the checkbox name the array name right? and then under it put a insert query like insert into table where id='$value'"; right?

Almost correct. When you submit the page, the checkboxes which were checked will be passed on to the next page. You can use foreach to get the checked values. Query the table and get the rows for these ID's.

<?php
foreach($_POST['checkboxname'] as $value){
$query = "select * from table where id='$value'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
 $school = $row['school'];
$date = $row['date']; //and so on..
//Then insert these values to the table
$insert = "insert into table2 (col1,col2) values ('$school','$date')";
mysql_query($insert);
}
}
//so, it will insert a row in the table for every checked checkbox value

I hope thats clear..

Thank u naveen once again for your help, ill try it looks right thanks

hello ive tried it and it says Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/stud/1/0472547/public_html/details.php on line 56

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.