Pass Data

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

Post Reply
Rosaka
Forum Newbie
Posts: 13
Joined: Mon Jan 10, 2011 2:00 pm

Pass Data

Post by Rosaka »

Hello, basically Ive got a description page, this page will be different depending on the product you click for its description. However its dosent seem to be working

<?php echo "<a href='http://127.0.0.1/desc.php?id=".$game->g ... ame()."</a>;" ?>

Thats where Im pretty sure the problem is happening, can anyone see a fault in that?

desc.php page works fine but desc.php?id=1, desc.php?id=2 etc wont work.
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: Pass Data

Post by anantha »

only thing i can notice is semi colon should be after "..like

Code: Select all

<?php echo "<a href='http://127.0.0.1/desc.php?id=".$game->getID()."'>".$game->getName()."</a>"; ?>
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Pass Data

Post by s992 »

Can we see the code you use to display the products?
Rosaka
Forum Newbie
Posts: 13
Joined: Mon Jan 10, 2011 2:00 pm

Re: Pass Data

Post by Rosaka »

I fixed it! =D

I did this instead

<a href="desc.php?id=<?php echo $game->getID(); ?>
&name=<?php echo $game->getName(); ?>"><?php echo $game->getName();?></a>

But now I have a little problem, what do I put in desc.php to "know" the id for the description that was clicked?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Pass Data

Post by Darhazer »

Rosaka wrote:But now I have a little problem, what do I put in desc.php to "know" the id for the description that was clicked?

Code: Select all

$_GET['id']
?
Rosaka
Forum Newbie
Posts: 13
Joined: Mon Jan 10, 2011 2:00 pm

Re: Pass Data

Post by Rosaka »

Hi thx, that worked kinda, its only showing the ID and not the other details I want. Heres what I got so far.

desc.php

<?php

$view->pageTitle = 'Desc';

$view->id = $_GET['id'];
$view->price = $_GET['Price'];
$view->date = $_GET['Date'];
$view->console = $_GET['Console'];
require_once('Views/desc.phtml');

desc.phtml

<?php require('template/header.phtml') ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<?php echo $view->id; ?>
<?php echo $view->price; ?>
<?php echo $view->date; ?>
<?php echo $view->console; ?>


</form>
<?php require('template/footer.phtml') ?>

Any idea how I can get price, date and console to show? and not just the ID
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Pass Data

Post by s992 »

$_GET is an array that holds paramaters passed via the URL. In your case, your URL would need to be something like http: //www.mysite.com/index.php?id=5&Price=25& ... le=console

However, I'm assuming that you are storing all this information in a DB, so you should take $_GET['id'] and query the DB for the proper information and set the variables accordingly:

Code: Select all

$sql = "SELECT * FROM products WHERE id = " . $_GET['id'];
$result = mysql_query($sql);
$row = mysql_fetch_row($result);

$view->id = $_GET['id'];
$view->price = $row['price'];
$view->date = $row['date'];
$view->console = $row['console'];
Last edited by s992 on Wed Jan 12, 2011 5:26 pm, edited 1 time in total.
Rosaka
Forum Newbie
Posts: 13
Joined: Mon Jan 10, 2011 2:00 pm

Re: Pass Data

Post by Rosaka »

Hi, I tried your advice but got the following errors

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given

Am guessing theres a problem connecting to the database? But I am already connected? I view the list of items from the database on the page, I then click that item to load up desc.php, but this is where the problem is going wrong :( I cant seem to pass/retrieve the specific item.

Im a total noob at this :(
Post Reply