FinnKim Posted May 3, 2012 Share Posted May 3, 2012 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 https://forums.phpfreaks.com/topic/262012-click-name-from-one-mysql-table-to-show-report-on-other-page/ Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2012 Share Posted May 3, 2012 $topic = $_GET['id']; Link to comment https://forums.phpfreaks.com/topic/262012-click-name-from-one-mysql-table-to-show-report-on-other-page/#findComment-1342654 Share on other sites More sharing options...
FinnKim Posted May 4, 2012 Author Share Posted May 4, 2012 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 https://forums.phpfreaks.com/topic/262012-click-name-from-one-mysql-table-to-show-report-on-other-page/#findComment-1342931 Share on other sites More sharing options...
kiqeri Posted May 8, 2012 Share Posted May 8, 2012 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 https://forums.phpfreaks.com/topic/262012-click-name-from-one-mysql-table-to-show-report-on-other-page/#findComment-1343878 Share on other sites More sharing options...
FinnKim Posted May 16, 2012 Author Share Posted May 16, 2012 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>"; Link to comment https://forums.phpfreaks.com/topic/262012-click-name-from-one-mysql-table-to-show-report-on-other-page/#findComment-1345818 Share on other sites More sharing options...
FinnKim Posted May 16, 2012 Author Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262012-click-name-from-one-mysql-table-to-show-report-on-other-page/#findComment-1345831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.