Help with passing id and field info?
Moderator: General Moderators
Help with passing id and field info?
Could someone please explain to me how to pass the id through a url so on the "receiving" page I can echo the data in the field of the id ?
Thank you!
Thank you!
Re: Help with passing id and field info?
Code: Select all
<a href="page.php?id=123">Link</a>Code: Select all
<?php // page.php
echo $_GET["id"]; // 123Re: Help with passing id and field info?
How would you point to the correct field with this code?tasairis wrote:Code: Select all
<a href="page.php?id=123">Link</a>Code: Select all
<?php // page.php echo $_GET["id"]; // 123
Re: Help with passing id and field info?
What field?
Re: Help with passing id and field info?
Any field I want to specify.
Re: Help with passing id and field info?
If I run this code like it is, it 's not pointing to a specific field, just a row, right? Or am I missing something?
Thanks for your help, just trying to learn.
Thanks for your help, just trying to learn.
Re: Help with passing id and field info?
Nothing is pointing anywhere. $id is just a number - you do whatever you want with it.
Have you read through the PHP manual recently?
Have you read through the PHP manual recently?
Re: Help with passing id and field info?
I think you're asking how an html form connects to php?
when ^ is submitted, the url will be file.php?somefield=what_you_type
Code: Select all
<input type="text" name="somefield" />Code: Select all
echo $_GET['somefield'];Re: Help with passing id and field info?
What I am trying to do is send the id of the product to the next page and in that page load the product description (desc). What I have so far is:
but url link is not echoed???
Code: Select all
<?php
$cat = $_GET['cat'];
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
echo '<a href="'.$sitelocation.$item_row['url'].'?item_desc='.$item_row['id'].'>view details/order</a>';
?>Re: Help with passing id and field info?
Where did you (not) get $item_row from?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Help with passing id and field info?
No echo at all? If so, then your code is never reaching that area.imimin wrote:but url link is not echoed???
If that's not what you mean, then you are not using mysql_query() correctly. The function mysql_query() performs a query which gives you a handle to the results of the query, not the results themselves. You must use that handle in order to retrieve your data. This can be done with mysql_fetch_*() functions, where * is "array", "assoc", "object", etc. The PHP manual should tell you all that you need to know in regards to how those functions work.
PHP does not magically create variables for you. $item_row needs to be initialized to have any value beyond NULL. I'm assuming that you are looking for this:
Code: Select all
$item_row = mysql_fetch_assoc($get_items);