| | |
PHP variable in link
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
I think I have read the answer reading through several forums and many posts, but I am not getting it. Please help... I am a novice.
I have a page that displays some info for all the records in a database. It's for real estate listings, so the page displays the street address, subdivision and a description of the property. This page is created dynamically from a database. This page is called allListings.php.
I would like to add a link to the street address that would take you to a detail page -- called inventory.php -- where more information about the property can be viewed.
Help?
Here is what my last try looked like:
<a href="\inventory.php?id=" . $id . "\"><?php echo $row_rsAllListings['element_1_1']; ?></a>
While inventory.php displays the information I want, it is pulling the first record in the database regardless of the property I click.
I have attached my two pages.
I have a page that displays some info for all the records in a database. It's for real estate listings, so the page displays the street address, subdivision and a description of the property. This page is created dynamically from a database. This page is called allListings.php.
I would like to add a link to the street address that would take you to a detail page -- called inventory.php -- where more information about the property can be viewed.
Help?
Here is what my last try looked like:
<a href="\inventory.php?id=" . $id . "\"><?php echo $row_rsAllListings['element_1_1']; ?></a>
While inventory.php displays the information I want, it is pulling the first record in the database regardless of the property I click.
I have attached my two pages.
<a href="\inventory.php?id=" . $id . "\"><?php echo $row_rsAllListings['element_1_1']; ?></a> Why do you echo $row_rsAllListings['element_1_1'] but you don't echo $id? Check the link href value after the page is loaded. I'm sure you'll spot the problem.
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
php Syntax (Toggle Plain Text)
<div class="content"> <table width="600"> <?php $counter = 0; // initialize counter outside loop do { echo '<tr'; if ($counter++ % 2) {echo 'class="hilite"';} echo '><td width="162"><img src="'.$row_rsAllListings['element_16'].'"></td>'; echo '<td width="426"><h2><a href="\inventory.php?id="'.$id.'">'.$row_rsAllListings['element_1_1']; echo '</a> | '.$row_rsAllListings['element_2'].'<br />'; echo $row_rsAllListings['element_3'].'</h2><br />'; echo $row_rsAllListings['element_4'].'<br />'; echo $row_rsAllListings['element_5'].'Beds / '.$row_rsAllListings['element_6']; echo $row_rsAllListings['element_7'].'Baths / '.$row_rsAllListings['element_8'].'sf per '.$row_rsAllListings['element_9'].'<br /></td></tr>'; } while ($row_rsAllListings = mysql_fetch_assoc($rsAllListings)); ?> </table> </div>
original code
php Syntax (Toggle Plain Text)
<div class="content"> <table width="600"> <?php $counter = 0; // initialize counter outside loop ?> <?php do { ?> <tr <?php if ($counter++ % 2) {echo 'class="hilite"';} ?>> <td width="162"><img src="<?php echo $row_rsAllListings['element_16']; ?>></td> <td width="426"> <h2><a href="\inventory.php?id=" . $id . "\"><?php echo $row_rsAllListings['element_1_1']; ?></a> | <?php echo $row_rsAllListings['element_2']; ?><br /> <?php echo $row_rsAllListings['element_3']; ?></h2> <br /> <?php echo $row_rsAllListings['element_4']; ?><br /> <?php echo $row_rsAllListings['element_5']; ?> Beds / <?php echo $row_rsAllListings['element_6']; ?>-<?php echo $row_rsAllListings['element_7']; ?> Baths / <?php echo $row_rsAllListings['element_8']; ?>sf per <?php echo $row_rsAllListings['element_9']; ?><br /> </td> </tr> <?php } while ($row_rsAllListings = mysql_fetch_assoc($rsAllListings)); ?> </table> </div>
Last edited by almostbob; Aug 18th, 2009 at 7:13 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
Okay, so now I have the correct id appearing at the top of the next page by editing the link to be:
But the record being displayed in that next page is always the first record in the database.
Progress for sure, but not there yet.
PHP Syntax (Toggle Plain Text)
<a href="\inventory.php?id=<?php echo $row_rsAllListings['id']; ?>"\><?php echo $row_rsAllListings['element_1_1']; ?></a>
But the record being displayed in that next page is always the first record in the database.
Progress for sure, but not there yet.
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
tryin the original code sample the php variable $id is not within aphp Syntax (Toggle Plain Text)
<tr <?php if ($counter++ % 2) { echo 'class="hilite"'; } echo '><td width="162"><img src='.$row_rsAllListings['element_16'].'></td><td width="426"><h2><a href=/"/inventory.php?id='.$row_rsAllListings['element_1_1'].'</a> | '.$row_rsAllListings['element_2'].'<br />'; ?><?php ?>block, =>cant be accessed
not sure what editor you are using,
but
when I pasted your code into notepad++ $id in this link was hilighted red immediately, v.easy to find
I have added the $id back into the code, but getting the same record on the next page regardless of the link I click.
Last edited by isak; Aug 18th, 2009 at 7:05 pm.
inventory.php
there is no 'select * from database where id='.$id
there is no reference to '$id' in the file
the href calling the inventory script
inventory.php?id=$id
if you don't use it, you lose it, and id is getting lost
there is no 'select * from database where id='.$id
there is no reference to '$id' in the file
the href calling the inventory script
inventory.php?id=$id
if you don't use it, you lose it, and id is getting lost
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
your link to inventory.php has a parameter ?id=$id
assuming $id is the id link of the record in the database
that id is available in inventory.php as $id
somewhere in the inventory.php file there should be (could be, usually is) an sql query that selects the row defined by that id
something like I could not find such query in the file
I could find many queries, but none that selected on the basis of $id
it may be as simple as finding the variable used in inventory.php to select and
change that named variable to $id /* or */
change the parameter name passed by the link to that used in inventory.php /* or */
add a sql select with the right format
the sql in the files is convoluted, almost as if written to hide its intent
assuming $id is the id link of the record in the database
that id is available in inventory.php as $id
somewhere in the inventory.php file there should be (could be, usually is) an sql query that selects the row defined by that id
something like
sql Syntax (Toggle Plain Text)
"select * from database where id=$id"
I could find many queries, but none that selected on the basis of $id
it may be as simple as finding the variable used in inventory.php to select and
change that named variable to $id /* or */
change the parameter name passed by the link to that used in inventory.php /* or */
add a sql select with the right format
the sql in the files is convoluted, almost as if written to hide its intent
Last edited by almostbob; Aug 18th, 2009 at 9:27 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
I edited the inventory.php file to include the $id. I just put it at the beginning of the street address however I really would rather it not appear in the inventory page when viewed. I have attached the new inventory.php file.
So while it *works* it is still only pulling the first record in the database.
The sql written in the file is written by Dreamweaver.
BTW... nice clean code that you wrote. Thanks.
So while it *works* it is still only pulling the first record in the database.
The sql written in the file is written by Dreamweaver.
BTW... nice clean code that you wrote. Thanks.
without debugging the code, don't have the db structure, don't know what table refers to what, you have to end up with something like horrible data structure ap_form.element_57, not at all intuitive
php Syntax (Toggle Plain Text)
mysql_select_db($database_rsGunn, $rsGunn); $query_rsInventory1 = "SELECT ap_form_1.element_1_1, ap_form_1.element_1_2, ap_form_1.element_1_3, ap_form_1.element_1_4, ap_form_1.element_1_5, ap_form_1.element_1_6, ap_form_1.element_2, ap_form_1.element_3, ap_form_1.element_16, ap_form_1.element_4, ap_form_1.element_5, ap_form_1.element_57, ap_form_1.element_6, ap_form_1.element_7, ap_form_1.element_8, ap_form_1.element_9, ap_form_1.id FROM ap_form_1 where id=".$id; $rsInventory1 = mysql_query($query_rsInventory1, $rsGunn) or die(mysql_error());
Last edited by almostbob; Aug 18th, 2009 at 11:40 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
![]() |
Similar Threads
- text field values to php variable....... (PHP)
- how to access accessing PHP variable in JavaScript (PHP)
- how to assign javascript variable to php variable (PHP)
- How to Wrap Text around an image when the imgsrc is in a PHP variable! (PHP)
- sql into php variable (PHP)
- HELP me pass php variable from a page to other (PHP)
- PHP Variable in mySQL query (PHP)
- How Can I Pass A PHP Variable From One .php page to another (PHP)
Other Threads in the PHP Forum
- Previous Thread: Users have to login and logout twice, why?
- Next Thread: Intergrating javascript with php / mysql
| Thread Tools | Search this Thread |
301 access apache api array beginner binary broken button cakephp checkbox class clean cms code countingeverycharactersfromastring crack cron curl database date decode directory display dissertation dropdown dynamic echo email error fairness file files folder form forms function functions google href htaccess html image include insert integration ip javascript joomla limit link login mail match md5 menu methods mlm multiple mysql newsletters oop pageing pagerank paypal pdf php problem protocol query radio random recursion remote script search secure server sessions simple sms soap source space spam sql syntax system table tutorial update upload url validator variable video virus votedown web youtube






