i have coded to display a search result, or results, in table, and what i need is a way to select that record and send it to another page. how can i select a record, if a radio button is added just before the result record, how can u click that record and send it to another page?


please help

Hy!

U should use GET. Print the records in an <a> (anchor element) and push the records after the site you are requesting. Like:

PHP-SQL:

$q=mysqli_query($dbc, "SELECT * FROM 'table_name' ");
ehco "<ul>";
while($row=mysqli_fetch_array($q)){ //or as u want assoc, object, row
      echo "<li><a href='somewhere.php?".$row["result_name"]."=".$row["result"]."'>".$row["result"]."</a></li>";
};
echo "</ul>";

Or you can use JavaScript for it. onclick event is good for the purpose. Depends on your GUI... =)


Try this dude! =) Hope I helped! =)

Be good!

shall i give u my code?? can u chck and show me how to do it?

<?php

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
$q=$_POST['q']; 
$id=$_POST['id']; 
//print $cs;
}

$con = mysql_connect('localhost', 'root', ''); 
if (!$con) 
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); 

extract($_POST);

if($q != '') {
	if($id != '') {
		$sql = "select * from course_participant where name LIKE '%$q%' and nic = '$id'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}else {
		$sql = "select * from course_participant where name LIKE '%$q%'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}
}else {
	if($id != '') {
		$sql = "select * from course_participant where nic = '$id'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}else if($sql<0){
		// error !!!
		$sql = false;
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
                echo "No Result Found!";
	}
}


if($sql) {
	$sql .= " and completed = '$cs'";
	
	// execution goes here!!!
} else if($sql) {

        $sql .=" and completed = '$pm'";

}

if($num_rows >0) {

echo "<table border='3'>";
echo "<tr style='background-color:#A9D0F5'> <th width='100'>CP_ID</th><th width='200'>Name</th><th width='350'>NIC</th><th width='750'>Address</th><th width='250'>Contact No</th><th width='250'>Email</th><th width='150'>Gender</th><th width='150'>Age</th><th width='200'>Marital Status</th><th width='300'>University</th><th width='300'>Fac/Dept</th><th width='300'>Course</th><th width='150'>Course Date</th><th width='150'>Reg. Date</th><th width='150'>Payments</th><th width='150'>Completion</th> </tr>";

while($row = mysql_fetch_array( $result )) {
//echo "<form name='tableform' method='get'>";
echo "<tr style='background-color:#CEE3F6'>"; 
echo "<td>";echo $row['CP_ID'];echo "</input>";echo "</td>"; 
echo "<td>";echo $row['name'];echo "</td>"; 
 echo "<td>";echo $row['nic'];echo "</td>"; 
 echo "<td>";echo $row['address'];echo "</td>"; 
 echo "<td>";echo $row['contact_no'];echo "</td>"; 
 echo "<td>";echo $row['email'];echo "</td>"; 
 echo "<td>";echo $row['gender'];echo "</td>"; 
 echo "<td>";echo $row['age'];echo "</td>"; 
 echo "<td>";echo $row['marital_status'];echo "</td>"; 
 echo "<td>";echo $row['university'];echo "</td>"; 
 echo "<td>";echo $row['facdept'];echo "</td>"; 
 echo "<td>";echo $row['course'];echo "</td>"; 
 echo "<td>";echo $row['course_date'];echo "</td>"; 
 echo "<td>";echo $row['reg_date'];echo "</td>"; 
 echo "<td>";echo $row['payments'];echo "</td>"; 
 echo "<td>";echo $row['completion'];echo "</td>"; 
echo "</tr>";
echo "<br>";

} 
echo "</table>";
?>

<html>
<form action="http://localhost/sdc/?q=node/3" method="post">
<input type="submit" value="EDIT" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/>
</form>
</html>

<?php

}

else if($num_rows<0) 
{
echo "No result found!"; 
}

mysql_close($con); 


?>

shall i give u my code?? can u chck and show me how to do it?

<?php

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
$q=$_POST['q']; 
$id=$_POST['id']; 
//print $cs;
}

$con = mysql_connect('localhost', 'root', ''); 
if (!$con) 
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); 

extract($_POST);

if($q != '') {
	if($id != '') {
		$sql = "select * from course_participant where name LIKE '%$q%' and nic = '$id'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}else {
		$sql = "select * from course_participant where name LIKE '%$q%'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}
}else {
	if($id != '') {
		$sql = "select * from course_participant where nic = '$id'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}else if($sql<0){
		// error !!!
		$sql = false;
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
                echo "No Result Found!";
	}
}


if($sql) {
	$sql .= " and completed = '$cs'";
	
	// execution goes here!!!
} else if($sql) {

        $sql .=" and completed = '$pm'";

}

if($num_rows >0) {

echo "<table border='3'>";
echo "<tr style='background-color:#A9D0F5'> <th width='100'>CP_ID</th><th width='200'>Name</th><th width='350'>NIC</th><th width='750'>Address</th><th width='250'>Contact No</th><th width='250'>Email</th><th width='150'>Gender</th><th width='150'>Age</th><th width='200'>Marital Status</th><th width='300'>University</th><th width='300'>Fac/Dept</th><th width='300'>Course</th><th width='150'>Course Date</th><th width='150'>Reg. Date</th><th width='150'>Payments</th><th width='150'>Completion</th> </tr>";

while($row = mysql_fetch_array( $result )) {
//echo "<form name='tableform' method='get'>";
echo "<tr style='background-color:#CEE3F6'>"; 
echo "<td>";echo $row['CP_ID'];echo "</input>";echo "</td>"; 
echo "<td>";echo $row['name'];echo "</td>"; 
 echo "<td>";echo $row['nic'];echo "</td>"; 
 echo "<td>";echo $row['address'];echo "</td>"; 
 echo "<td>";echo $row['contact_no'];echo "</td>"; 
 echo "<td>";echo $row['email'];echo "</td>"; 
 echo "<td>";echo $row['gender'];echo "</td>"; 
 echo "<td>";echo $row['age'];echo "</td>"; 
 echo "<td>";echo $row['marital_status'];echo "</td>"; 
 echo "<td>";echo $row['university'];echo "</td>"; 
 echo "<td>";echo $row['facdept'];echo "</td>"; 
 echo "<td>";echo $row['course'];echo "</td>"; 
 echo "<td>";echo $row['course_date'];echo "</td>"; 
 echo "<td>";echo $row['reg_date'];echo "</td>"; 
 echo "<td>";echo $row['payments'];echo "</td>"; 
 echo "<td>";echo $row['completion'];echo "</td>"; 
echo "</tr>";
echo "<br>";

} 
echo "</table>";
?>

<html>
<form action="http://localhost/sdc/?q=node/3" method="post">
<input type="submit" value="EDIT" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/>
</form>
</html>

<?php

}

else if($num_rows<0) 
{
echo "No result found!"; 
}

mysql_close($con); 


?>

shall i give u my code?? can u chck and show me how to do it?

Copy-Paste it here, so everybody who's interrested in this subject can help, or learn from it! =)

hi are u checking my code "benkus" ? pls help asap!

hi are u checking my code "benkus" ? pls help asap!

Yes yes please wait a little more! =)

ok so i did it in a way CP_ID is linked with the edit page like this

while($row = mysql_fetch_array( $result )) {
echo "<form name='tableform' method='get'>";
echo "<tr style='background-color:#CEE3F6'>"; 
//echo "<a href='http://localhost/sdc/?q=node/3'>EDIT";
echo "<td>";echo "<a href='http://localhost/sdc/?q=node/3'>";echo $row['CP_ID'];echo "</td>"; 
echo "<td>";echo $row['name'];echo "</td>"; 
 echo "<td>";echo $row['nic'];echo "</td>"; 
 echo "<td>";echo $row['address'];echo "</td>"; 
 echo "<td>";echo $row['contact_no'];echo "</td>"; 
 echo "<td>";echo $row['email'];echo "</td>"; 
 echo "<td>";echo $row['gender'];echo "</td>"; 
 echo "<td>";echo $row['age'];echo "</td>"; 
 echo "<td>";echo $row['marital_status'];echo "</td>"; 
 echo "<td>";echo $row['university'];echo "</td>"; 
 echo "<td>";echo $row['facdept'];echo "</td>"; 
 echo "<td>";echo $row['course'];echo "</td>"; 
 echo "<td>";echo $row['course_date'];echo "</td>"; 
 echo "<td>";echo $row['reg_date'];echo "</td>"; 
 echo "<td>";echo $row['payments'];echo "</td>"; 
 echo "<td>";echo $row['completion'];echo "</td>"; 
 echo "<td>";echo $row['current'];echo "</td>"; 
echo "</tr>";
echo "<br>";

} 
echo "</table>";
?>

what do u think? but i need this entered values to show in the edit pages text fields - how do u make it so that values can be shown in text fields?

Done! =)

The file is called "showresult.php, this is important!

Ok. I'm thinking about something like this:

<html>
<body>
<?php
$con=mysqli_connect('localhost', 'root', '', 'sdc_cpds');
if(!$con){
	die('Could not connect: '.mysqli_connect_error());
};
if(isset($_GET['id'])&&isset($_GET['name'])){
	$id=$_GET["id"];
	$name=$_GET["name"];
	$sql="SELECT * FROM course_participant WHERE name LIKE '$id' AND nic = '$name'";
        sqlQuery($sql);
} else if(isset($_POST['find'])&&isset($_POST['cs'])&&isset($_POST['q'])&&isset($_POST['id'])){
	$cs=$_POST['cs'];
	$q=$_POST['q'];
	$id=$_POST['id'];
	if($q!=''&&$id!=''){
		$sql="SELECT * FROM course_participant WHERE name LIKE '%$q%' AND nic='$id'";
		sqlQuery($sql);
	} else if($q!=''){
		$sql="SELECT * FROM course_participant WHERE name LIKE '%$q%'";
		sqlQuery($sql);
	} else if($id!='') {
		$sql="SELECT * FROM course_participant WHERE nic='$id'";
		sqlQuery($sql);
	};
};
mysql_close($con);

function sqlQuery($query){
	if($query!=''){
		echo "<table border='3'>";
		echo "<tr style='background-color:#A9D0F5'>
			<th width='100'>CP_ID</th>
			<th width='200'>Name</th>
			<th width='350'>NIC</th>
			<th width='750'>Address</th>
			<th width='250'>Contact No</th>
			<th width='250'>Email</th>
			<th width='150'>Gender</th>
			<th width='150'>Age</th>
			<th width='200'>Marital Status</th>
			<th width='300'>University</th>
			<th width='300'>Fac/Dept</th>
			<th width='300'>Course</th>
			<th width='150'>Course Date</th>
			<th width='150'>Reg. Date</th>
			<th width='150'>Payments</th>
			<th width='150'>Completion</th> 
			</tr>";
		$result=mysqli_query($con, $query);
		while($row=mysqli_fetch_assoc($result)){
			echo "<tr style='background-color:#CEE3F6'>";
			echo "<td>".$row['CP_ID']."</td>";
			echo "<td><a href='showresult.php?id=".$row['CP_ID']."&name=".$row['name']."'>".$row['name']."</a></td>"; // change the 'showresult.php" to your link!!!
			echo "<td>".$row['nic']."</td>";
			echo "<td>".$row['address']."</td>";
			echo "<td>".$row['contact_no']."</td>";
			echo "<td>".$row['email']."</td>";
			echo "<td>".$row['gender']."</td>";
			echo "<td>".$row['age']."</td>";
			echo "<td>".$row['marital_status']."</td>";
			echo "<td>".$row['university']."</td>";
			echo "<td>".$row['facdept']."</td>";
			echo "<td>".$row['course']."</td>";
			echo "<td>".$row['course_date']."</td>";
			echo "<td>".$row['reg_date']."</td>";
			echo "<td>".$row['payments']."</td>";
			echo "<td>".$row['completion']."</td>";
			echo "</tr>";
		}; //while end
		echo "</table>";
	} else {
		echo "No ID, or no Q given!";
	};
};
?>
</body>
</html>

I think it should work for you! =) Have fun with it, or modify it! =)

Best regards!

ok so i did it in a way CP_ID is linked with the edit page like this

while($row = mysql_fetch_array( $result )) {
echo "<form name='tableform' method='get'>";
echo "<tr style='background-color:#CEE3F6'>"; 
//echo "<a href='http://localhost/sdc/?q=node/3'>EDIT";
echo "<td>";echo "<a href='http://localhost/sdc/?q=node/3'>";echo $row['CP_ID'];echo "</td>"; 
echo "<td>";echo $row['name'];echo "</td>"; 
 echo "<td>";echo $row['nic'];echo "</td>"; 
 echo "<td>";echo $row['address'];echo "</td>"; 
 echo "<td>";echo $row['contact_no'];echo "</td>"; 
 echo "<td>";echo $row['email'];echo "</td>"; 
 echo "<td>";echo $row['gender'];echo "</td>"; 
 echo "<td>";echo $row['age'];echo "</td>"; 
 echo "<td>";echo $row['marital_status'];echo "</td>"; 
 echo "<td>";echo $row['university'];echo "</td>"; 
 echo "<td>";echo $row['facdept'];echo "</td>"; 
 echo "<td>";echo $row['course'];echo "</td>"; 
 echo "<td>";echo $row['course_date'];echo "</td>"; 
 echo "<td>";echo $row['reg_date'];echo "</td>"; 
 echo "<td>";echo $row['payments'];echo "</td>"; 
 echo "<td>";echo $row['completion'];echo "</td>"; 
 echo "<td>";echo $row['current'];echo "</td>"; 
echo "</tr>";
echo "<br>";

} 
echo "</table>";
?>

Form in a loop??? Let's say u have 50 rows in your table, and u want to print out 50 forms in a page? That's a bit much don't u think? =)

Try my version, I hope it works! =)

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.