I have below a quite simple php page which queries a database table of all
records and outputs the result. However on this page I only output 3 of the
fields and I would like to click on a particular row which would then bring
up a detail page (which displays all the fields (perhaps 10 or more) of that
record).
Do I create another php file called detail.php which includes the line:
$sql = 'SELECT * FROM `link` WHERE link_id = $id;
and then alter the echo line below to something like:
echo "<TR><TD><a
href=detail.php?link_id=$id</TD><TD>$title</TD><TD>$description</TD></TR>";
which would then pass the variable $id into the sql statement in detail.php.
??
Any advice on the next steps would be welcome.
Cheers
Phil
<html>
<body>
<?php
// listrecords.php
// lists brief details of records (1 record per row)
$localhost = 'localhost';
$username = 'username';
$password = 'password';
$database = 'database';
$dbconnection = mysql_connect($localhost, $username, $password);
if (! $dbconnection)
{
die ("Couldn't connect to MySQL");
exit;
}
$db=mysql_select_db($database, $dbconnection);
if (!$db)
{
echo "Could not select database";
exit;
}
$sql = 'SELECT `link_id`,`title`,`description` FROM `links` LIMIT 0, 30';
$mysql_result=mysql_query($sql,$dbconnection);
$num_rows=mysql_num_rows($mysql_result);
if ($num_rows == 0) {
echo "Sorry, we have no records";
}
else
{
echo "<TABLE ALIGN=\"CENTER\" BORDER=\"1\">";
echo "<TR><TH>Record ID</TH><TH>Title</TH><TH>Description</TH></TR>";
while ($row=mysql_fetch_array($mysql_result))
{
$id=$row["link_id"];
$title=$row["title"];
$description=$row["description"];
echo "<TR><TD>$id</TD><TD>$title</TD><TD>$description</TD></TR>";
}
}
?>
</TABLE>
</body>
</html> 4 1339
Phil Latio wrote: I have below a quite simple php page which queries a database table
of all records and outputs the result. However on this page I only output 3
of the fields and I would like to click on a particular row which would then
bring up a detail page (which displays all the fields (perhaps 10 or more)
of that record).
Do I create another php file called detail.php which includes the
line:
yes, that is a way
$sql = 'SELECT * FROM `link` WHERE link_id = $id;
this is not so good, because:
1. if register_globals is off (which it should be), $link_id gets not
automatically registered. use $_GET['link_id']
2. $_GET['link_id'] is user submitted data, so never ever trust it.
validate. i suppose your id's are integers, so using
(int)$GET_['link_id'] forces anything that is sent into an integer,
which in the worst case is just 0.
and then alter the echo line below to something like: echo "<TR><TD><a
href=detail.php?link_id=$id</TD><TD>$title</TD><TD>$description</TD></TR>";
yes, like that.
micha
> > $sql = 'SELECT * FROM `link` WHERE link_id = $id; this is not so good, because:
1. if register_globals is off (which it should be), $link_id gets not automatically registered. use $_GET['link_id']
2. $_GET['link_id'] is user submitted data, so never ever trust it. validate. i suppose your id's are integers, so using (int)$GET_['link_id'] forces anything that is sent into an integer, which in the worst case is just 0.
Many thanks for replying.
Are you suggesting something along these lines?
$specific_link = (int)$_GET['link_id'];
$sql = 'SELECT * FROM `link` WHERE link_id = $specific_link;
Cheers
Phil
Phil Latio wrote: $sql = 'SELECT * FROM `link` WHERE link_id = $id;
this is not so good, because:
1. if register_globals is off (which it should be), $link_id gets
not automatically registered. use $_GET['link_id']
2. $_GET['link_id'] is user submitted data, so never ever trust it. validate. i suppose your id's are integers, so using (int)$GET_['link_id'] forces anything that is sent into an integer, which in the worst case is just 0.
Many thanks for replying.
Are you suggesting something along these lines?
$specific_link = (int)$_GET['link_id']; $sql = 'SELECT * FROM `link` WHERE link_id = $specific_link;
Cheers
Phil
yes.
general.php contains
<a href=detail.php?link_id=YOUR_INT_VALUE>link</a>
and detail.php copntains the above code.
micha
> yes. general.php contains
<a href=detail.php?link_id=YOUR_INT_VALUE>link</a>
and detail.php copntains the above code.
micha
Thanks again.
Cheers
Phil This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
Those of you with backgrounds with the C language will laugh at my
mistake, but those of you, like myself, who deal mostly with PHP
should be warned about passing variables as references -...
|
by: Matthew Robinson |
last post by:
i read a tutorial the other day on passing variables between php pages
using a html form and setting the action to the php page to parse, can
anybody see anything wrong with the code below? the...
|
by: Chieko Kuroda |
last post by:
Hello all,
I would like to learn the syntax for passing variables that I retreived from
a database to a second asp page. Currently, I'm using:
Response.Write "<tr><td> </td><td><Font size=...
|
by: Consuelo Guenther |
last post by:
Hello,
I am having problems with passing variables between pages. I have the
following:
First asp page has the function:
-----------------------------------------------------------------------...
|
by: Khai |
last post by:
First off, yes, I understand the crapload of tutorials out there, (well,
rather, I understand there /are/ a crapload of tutorials out there), the
problem is my comprehension.
I'm trying to pass...
|
by: jsdeveloper |
last post by:
Hi,
I just started programming in javascript, and I'm having a problem passing variables between javascript and asp code in .asp page. Can you please help?
I've given the sample code below.
...
|
by: satterfieldben |
last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call...
|
by: Shawn Northrop |
last post by:
test.php:
<?php
$d=$_GET;
echo $d;
?>
when i go to
www....com/test.php?data=1
nothing happens.
|
by: coool |
last post by:
Hi :)
anyone knows how can I send variables from a php page to a form - i need to fill the form with these variables ?
maybe using (the process of passing variables to other pages - through...
|
by: BezerkRogue |
last post by:
This is the most fundamental action I am sure, but I can't seem to make it happen.
I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |