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);
  }
?> 

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.