PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tom.cull
Forum Commoner
Posts: 32 Joined: Tue Sep 06, 2005 9:31 am
Post
by tom.cull » Fri Sep 09, 2005 8:24 am
Hi,
i have a page where I can list the contents of a db:
Code: Select all
<html>
<body>
<?php
// listing script
$username="xxxx_xxxx";
$password="xxxx";
$database="xxxx_xxxx";
$table="xxxx_xxxx";
// connect to the server
mysql_connect( 'localhost',$username,$password)
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( $database)
or die( "Error! Could not select the database: " . mysql_error() );
// retrieve all the rows from the database
$query = "SELECT * FROM $table ORDER BY `contact_nlast`, `contact_nfirst`";
$results = mysql_query( $query );
// print out the results
if( $results )
{
while( $contact = mysql_fetch_object( $results ) )
{
// print out the info
$id = $contact -> id;
$contact_nlast = $contact -> contact_nlast;
$contact_nfirst = $contact -> contact_nfirst;
echo( "$id, $contact_nlast, $contact_nfirst<br>" );
}
}
else
{
die( "Trouble getting contacts from database: " . mysql_error() );
}
?>
</body>
</html>
This works fine. But i want to make it so that each item of the list is linked to a edititem.php page, passing on the id.
I have tried with putting in the below but it didnt work:
Code: Select all
$row = mysql_fetch_array( $result );
echo( "<a href=\"editdetails.php?id=".$row['id']."\">".$row['id']." . ".$row['contact_nfirst']." ".$row['contact_nlast']." - ".$row['car_make']."</a><br />" );
could one of you great experts help me out - im learning, just not quick enough!
Last edited by
tom.cull on Fri Sep 09, 2005 9:20 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 09, 2005 8:46 am
tried that where? it doesn't jive with your code all that well...
It may be a good time to start using
Code: Select all
tags when you are posting php code now..
tom.cull
Forum Commoner
Posts: 32 Joined: Tue Sep 06, 2005 9:31 am
Post
by tom.cull » Fri Sep 09, 2005 9:02 am
i tried the following:
Code: Select all
// retrieve all the rows from the database
$query = "SELECT * FROM $table ORDER BY `contact_nlast`, `contact_nfirst`";
$results = mysql_query( $query );
// print out the results
if( $results )
{
while( $contact = mysql_fetch_object( $results ) )
{
// print out the info
$id = $contact -> id;
$contact_nlast = $contact -> contact_nlast;
$contact_nfirst = $contact -> contact_nfirst;
echo( "<a href=\"editdetails.php?id=".['id']."\">".$['id']." . ".['contact_nfirst']." ".['contact_nlast']." - ".['car_make']."</a><br />" );
}
}
else
{
die( "Trouble getting contacts from database: " . mysql_error() );
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 09, 2005 9:05 am
try this instead
Code: Select all
$id = $contact -> id;
$contact_nlast = $contact -> contact_nlast;
$contact_nfirst = $contact -> contact_nfirst;
echo( "<a href=\"editdetails.php?id={$id}\">{$id} . {$contact_nfirst} {$contact_nlast} - {$car_make}</a><br />" );
tom.cull
Forum Commoner
Posts: 32 Joined: Tue Sep 06, 2005 9:31 am
Post
by tom.cull » Fri Sep 09, 2005 9:19 am
your nothing short of a genius- thankyou !