0

Question is:

I have a PHP webpage with list of data taken from database.

---------------------------------------
----- ID117 ----- aaa ------ bbb ------
----- ID118 ----- aaa ------ bbb ------
----- ID119 ----- aaa ------ bbb ------
----- ID120 ----- aaa ------ bbb ------
----- ID121 ----- aaa ------ bbb ------
---------------------------------------

All what i need is: by clicking ID120 for example, it will open separate webpage with information from another database WHERE ID = ID120.

EG:

Click ID120:

Another page opened with this info:

ID120

City = UK,

Phone number = 1234234124

and so on....

I have this code:

<html>
<body>

<?php

include 'connect/con.php';

$result = mysqli_query($con,"SELECT * FROM newsvid");

echo "<table border='1'>
<tr>
<th>id</th>
<th>vidTitle</th>
<th>imgCover</th>
<th>vidSD</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['vidTitle'] . "</td>";
  echo "<td>" . $row['imgCover'] . "</td>";
  echo "<td>" . $row['vidSD'] . "</td>";
  echo "</tr>";
}

echo "</table>";

mysqli_close($con);
?>

</body>
</html>

I have another database called videoInformation so I need, by clicking ID open another webpage with information from another database where ID = which one was clicked.

Basically I'm not sure where to start. (

Denis
  • 103
  • 3
  • 10
  • 1
    We answer questions related to source code problems and programming. Which exact problem with your code do you face? In other words: Please show your source and what you have tried so far. What is working - what is not... – Jens A. Koch Oct 20 '14 at 22:44
  • Updated, have a look – Denis Oct 20 '14 at 22:48
  • Thanks. Now we have something we can work with. – Jens A. Koch Oct 20 '14 at 22:50
  • create a link on each row with the id in a get parameter. then use a prepared statement to retrieve the info for that id. – blots Oct 20 '14 at 22:56

2 Answers2

0
 echo '<td><a href="details.php?id='.$row['id'].'">'.$row['id'].'</a></td>';

on details.php, check the id $_GET['id'] and use that in the query for the details

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • and on details.php page how do display info where ID = clicked one? SELECT * FROM videoInformation WHERE id = id? ... sorry confused a bit, but you mostly solved my problem. – Denis Oct 20 '14 at 23:04
0

Currently you have just the output of the database:

echo "<td>" . $row['id'] . "</td>";

Let's change that to include a link:

echo '<td><a href="videoinfo.php?id=' . $row['id'] . '">' . $row['vidTitle'] . '</a></td>';

We added the <a> (anchor) tag for a html link. The href attribute points to videoinfo.php. This file will be used for your videoInformation querying. We are passing the $row['id'] via a GET request to the videoinfo.php by simply appending to the href URL.


Then create a file videoinfo.php:

<?php

// here we get the incomming video id (videoinfo.php?id=123)
$video_id = $_GET['id'];

// build a database query to select the videoInformation
// here we use WHERE to select the video_id we want
$query = 'SELECT * FROM videoInformationTable WHERE video_id = ' . $video_id;

// lets connect and do the query
include 'connect/con.php';
$result = mysqli_query($con, $query);

--

Important Note: When working with a database you should read about "SQL injection" and "escaping". You are working with mysqli, so please read about a function called real_escape_string() The manual also includes an example on how to apply the escaping correctly.

Also: How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
  • want to sanitise that before his database gets destroyed. oh and the link aint right –  Oct 20 '14 at 23:02
  • You should link to some helpful topics on SQL Injection. If he takes your code and uses it as is (lots of people do) he'll get annihilated... – visevo Oct 20 '14 at 23:03
  • He is a beginner - he wants to get started. But you both learned about SQL injection before build a anchor tag, right.. come on.. Also: this question is not about, how can i secure my video database which has 1 mio hits... – Jens A. Koch Oct 20 '14 at 23:05
  • Basically for now I try to understand basic idea, after i will improve the code and will read more about it. – Denis Oct 20 '14 at 23:13