Forum Moderators: coopster

Message Too Old, No Replies

dynamic links

passing php varibles from page to page

         

philhazard

2:20 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



Hi nice forum,

im relativly new to php and i have a problem. I have built a searchable database and a page to search it. This all works. At the moment it returns simplified results and i have a link "more info" below each result, i have managed to create a link that will pass the Primary key of the database to a new page in this case called "Ref" e.g.

/mysql/details.php?Ref=115

but i dont have a clue how to display the full results on a new page i have tried alot of ways none seem to work. All i need to do is display the corrosponding row! its so frustrating! any help would be wicked!

cheers phil

[edited by: philhazard at 2:31 pm (utc) on Sep. 5, 2005]

helenp

2:29 pm on Sep 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First of all,
we are not allowed to put links in the posts.

Second,
If I understood you correctly,
on the new page you need to get the variable in the query using get: like this: SELECT whatever FROM table1 WHERE id='$_GET[id]'

And in the link more info:
<a href=new_page.php?id=".$row["id"].">

joedub

2:33 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



the page you are linking to, "details.php" should do something like this...

1. fetch the "Ref" from _GET.

$ref = intval( $_GET['Ref'] );

2. execute a database query and retrieve the data however u are doing it, something like

$record = $db->fetch_records( "SELECT * FROM your_table WHERE RefField=$ref" );

3. output
if(! empty( $record ) )
{
echo "$record[Field1] $record[Field2]";
}
else
{
echo "No record was found!";
}

philhazard

4:09 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



Thanks for the help, however i get this error:

Fatal error: Call to a member function on a non-object

refering to this line:

$record = $db->fetch_records( "SELECT * FROM icepro WHERE RefField=$ref" );

i know its not that complicated but having real problems finding useful info on it!

does anybody know of a good tutorial to do with this, I dont understand it fully and want to!

sorry about the link, changed it now.

cheers,

coopster

9:05 pm on Sep 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



In our PHP Forum Library [webmasterworld.com] there is a good starter tutorial on the Basics of extracting data from MySQL [webmasterworld.com]. Have you read through that yet?

dkin

3:58 am on Sep 7, 2005 (gmt 0)

10+ Year Member



$record = $db->fetch_records( "SELECT * FROM icepro WHERE RefField=$ref" );

RefField is the name of the column with the unique variable that you have passed from the previous page.

So if you want to link shoes your db may look like this

hat ¦ shirt ¦ socks ¦ shoes

those are your columns

a row like this

baseball ¦ knitted ¦ ankle ¦ reebok

so your variable would look like this

/mysql/details.php?type=reebok

then on the new page have a query like so

$record = $db->fetch_records( "SELECT * FROM your_table WHERE shoes=$type" );

make sure you connect to the db with the query and you should be set.

hope it helps.

Dylan

philhazard

11:31 am on Sep 7, 2005 (gmt 0)

10+ Year Member



This is how i solved it in the end, Thanks for your help, it was thought provoking, and i will read thoese tutorials.

cheers phil

if($_GET['Ref'])
{
$query = 'select * from icepro where Ref='.$_GET['Ref'];
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);
echo '<div id="ContentCopy2">';
echo '<br>';
echo '<span class="headerbold16"> '.stripslashes($row['HotelName']).'</span> ';
echo '<br>';
echo '<br>';
echo '<strong> '.stripslashes($row['HotelGroup']).' ';
echo '<br>';
echo 'Town/City:</strong> '.stripslashes($row['TownCity']).' ';
echo '<br>';
echo '<strong>County:</strong> '.stripslashes($row['CountyState']).' ';
echo '<br>';
echo '<strong>Description:</strong> '.stripslashes($row['GeneralDescription']).' ';
echo '<br>';
echo '<strong>Tel:</strong> '.stripslashes($row['Tel']).' ';
echo '<br>';
echo '<strong>Fax:</strong> '.stripslashes($row['Fax']).' ';
echo '<br>';
echo '<a href="mailto:'.stripslashes($row['Email']).'">email</a> ';
echo '<br>';
echo '<strong>Website:</strong> '.stripslashes($row['Website']).' ';
echo '<br>';
echo '<strong>CarPark:</strong> '.stripslashes($row['CarPark']).' ';
echo '<br>';
echo '<strong>Contact:</strong> '.stripslashes($row['Contact']).' ';
echo '<br>';
echo '<strong>Check In:</strong> '.stripslashes($row['CheckIn']).' ';
echo '<br>';
echo '<strong>Check out:</strong> '.stripslashes($row['Checkout']).' ';
echo '<br>';
echo '<strong>Number of rooms:</strong> '.stripslashes($row['Numberofrooms']).' ';
echo '<br>';
echo '<strong>EnSuite:</strong> '.stripslashes($row['EnSuite']).' ';
echo '<br>';
echo '<strong>Single Sex Bookings:</strong> '.stripslashes($row['SingleSexBookings']).' ';
echo '<br>';
echo '<strong>Menu:</strong> '.stripslashes($row['Menu']).' ';
echo '<br>';
echo '<strong>Disabled:</strong> '.stripslashes($row['DisabledFacilities']).' ';
echo '<br>';
echo '<strong>BabySitting/listening:</strong> '.stripslashes($row['BabySitting/listening']).' ';
echo '<br>';
echo '<strong>Leisure Facilities:</strong> '.stripslashes($row['LeisureFacilities']).' ';
echo '<br>';
echo '<strong>Golf Facilities:</strong> '.stripslashes($row['GolfFacilities']).' ';
echo '<br>';
echo '<strong>Child Free Age:</strong> '.stripslashes($row['ChildFreeAge']).' ';
echo '<br>';
echo '<strong>Offer:</strong> '.stripslashes($row['Offer']).' ';