Jump to content

Click name from one mysql table to show report on other page


FinnKim

Recommended Posts

Hi,

 

How can I get others informations on another page by clicking on one row's value

 

I have this code, but it doesn't work:

 

while($row = mysql_fetch_array($result))
  {
echo "<tr><p>";

  echo "<th><p>" . $row['fname'] . "   " . $row['lname'] . "</p></th>";
  echo"<th><p><a href='student.php?id='".$row['topic']."'\'>".$row['topic']."</p></a></th>";

  echo "</tr>";
  }
echo "</table>";

 

 

Student.php

 

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

mysql_select_db("college", $con);

$result = mysql_query("SELECT * FROM students");
$topic = $_Get['topic'];
while($row = mysql_fetch_array($result))
  {
  
echo "<tr><p>";
  echo "<th><p>" . $row['month']." " .$row['datetime']."</p></th>";
  echo"<th><p>". $row['topic'] ."</p></th>"; 
  echo "<th><p>" . $row['gender'] . "</p></th>";
  echo "<th><p>" . $row['fname'] . "   " . $row['lname'] . "</p></th>";
  echo "<th ><p>" . $row['id'] . "</p></th>";
  echo "</tr>";
  
echo "</table>";

mysql_close($con);
  }
?> 

I tried this, but it still does'nt work?

 

 

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

mysql_select_db("college", $con);

$result = mysql_query("SELECT * FROM students");
$topic = $_Get['id'];


echo "<table>
    <tr>
        <th>" $topic->['fname']"</th>"
	"<td>"$topic->['lname']"</td>
        <th>"$topic->['email']"</th>
        <td>"$topic->['gender']"</td>";   

echo "</table>";

mysql_close($con);
  
?> 

 

I think there is something wrong with tis one also

 

echo"<th><p><a href='student.php?id='".$row['topic']."'\'>".$row['topic']."</p></a></th>";

how is the latest result? Does it giving you all the query from your database?

Maybe it should be this:

 

$topic = $_Get['id'];
$result = mysql_query("SELECT * FROM students WHERE topic LIKE'%$topic%'");

while($row = mysql_fetch_array($result))
  {
echo "<tr><p>";
  echo "<th><p>" . $row['month']." " .$row['datetime']."</p></th>";
  echo"<th><p>". $row['topic'] ."</p></th>"; 
  echo "<th><p>" . $row['gender'] . "</p></th>";
  echo "<th><p>" . $row['fname'] . "   " . $row['lname'] . "</p></th>";
  echo "<th ><p>" . $row['id'] . "</p></th>";
  echo "</tr>";
  
echo "</table>";

 

Because if the $result is $result = mysql_query("SELECT * FROM students)

then the looping will fetch all the array because your $result doesn't have condition.

 

 

  Quote

how is the latest result? Does it giving you all the query from your database?

. Before it printed all the query, but since I've changed it, it just print this line:"Warning: mysql_query() expects parameter 1 to be string, resource given". ???

 

My code looks like this now:

 

if (!isset($_GET['v_topic'])) {
$st =($_GET['v_topic']);
} else {
$st = 1;
}
$topic = $_Get['id'];
$query = mysql_query("SELECT * FROM students WHERE topic LIKE'%$st%'");
$result=mysql_query($query) or die (mysql_error());
if($row = mysql_fetch_array($result))
  {
echo "<tr><p>";
  echo"<th><p>"  . $row['topic'] ."</p></th>"; 
  echo "<th><p>" . $row['gender'] . "</p></th>";
  echo "<th><p>" . $row['fname'] . "   " . $row['lname'] . "</p></th>";
  echo "<th><p>" . $row['email'] .  "</p></th>";
  echo "<th><p>" . $row['assigned'] .  "</p></th>";
  echo "</tr>";
  }
  else
{
mysql_error();

}
echo "</table>";
?>

 

Do you know, if this is ok?

 

 echo"<th><a href='../student.php'=?id=".$row['topic']."'>".$row['topic']."</a></th>";

This is the last version of my code :)

 

if(!isset ($_SESSION['v_topic'])){
$_SESSION['v_topic'] = 'topic';}

$_SESSION['v_topic'] = $_Get['id'];
$query = mysql_query("SELECT * FROM students WHERE topic LIKE'"%$_SESSION['v_topic']%"'");
$result=mysql_query($query) or die (mysql_error());
if($row = mysql_fetch_array($result))
  {
echo "<tr><p>";
  echo"<th><p>"  . $row['studentId'] ."</p></th>"; 
  echo "<th><p>" . $row['gender'] . "</p></th>";
  echo "<th><p>" . $row['fname'] . "   " . $row['lname'] . "</p></th>";
  echo "<th><p>" . $row['email'] .  "</p></th>";
  echo "<th><p>" . $row['assigned'] .  "</p></th>";
  echo "</tr>";
  }
  else
{
mysql_error();

}

 

and this is the link:

 

echo"<th><a href='../student.php'=?id=".$row['topic']."'>".$row['topic']."</a></th>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.