dpabla Posted December 23, 2006 Share Posted December 23, 2006 here is an example site of what I am doing:www.leohamel.com/test/jewelryThe user clicks on the brand name lets say Hearts on Fire and than page2.php should remember the vendorID number and also bring up contents of the category table (rings, bracelets, necklaces etc...) and these categories will be clickable links to page3.php which will than show sub-categories.I am having problems trying to create the multiple hyperlink variable code....also I have a quick question, the vendorID number wont be used till page3.php so logically vendorID should still be accessible by page3.php (meaning being passed on 3x) to be used on page3.phpHere is my code for page1.php[code]<?phpinclude('db_connect');?><center><table width="300" border="0" bordercolor="#000000" cellspacing="2" cellpadding="0"><tr align=center><td><?php$result = mysql_query("select * from vendors");while($r=mysql_fetch_array($result)){$vid=$r["vendor_id"];$vendorname=$r["vendor_name"];echo "<a href='page2.php?vid=" . $vid . "'>" . $vendorname . "</a>";echo "</tr></td>";}?>[/code]than the variable vendorID gets passed onto page2.php (lets say user clicks on Hearts on Fire): the categories should be listed but they arent...here is the code for page2.php:[code]<?php$result = mysql_query("select * from category");while($r2=mysql_fetch_array($result)){ $cid=$r2["category_id"];$categoryname=$r2["category_name"];echo "<a href='page3.php?vid=" . $vid . "&". $cid . "'>" . $categoryname . "</a><br>";?>[/code]Thanks so much for your help. As a side note, page3.php will than pull up the Sub-Category table that will than liste all the sub-categories for lets say Rings > Engagement Sets, Wedding Bands, Mens When a user clicks on Engagement Sets > than the vendorID is used to pull ALL products from the products table; items that match vendorID # Does that make sense? But I am stuck at multiple variables as I will be passing quite a bit....thanks again for your help everyone! Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/ Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 [code]echo "<a href='page3.php?vid=" . $vid . "&cid=". $cid . "'>" . $categoryname . "</a><br>";[/code]You need to specify what the second var is. Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147077 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 ok I tried that but the categories arent being listed and the page is blank....here is the code:[code]<?php$result = mysql_query("select * from category");while($r2=mysql_fetch_array($result)){ $cid=$r2["category_id"];$categoryname=$r2["category_name"];// echo "$categoryname";echo "<a href='page3.php?vid=" . $vid . "&cid=". $cid . "'>" . $categoryname . "</a><br>";?>[/code][quote author=jesirose link=topic=119780.msg490855#msg490855 date=1166913129][code]echo "<a href='page3.php?vid=" . $vid . "&cid=". $cid . "'>" . $categoryname . "</a><br>";[/code]You need to specify what the second var is.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147081 Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 Okay, booooo for using frames.Your while loop isn't closed. The page won't load because of that. Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147082 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 haha that was dumb....arite I Tried that and i am still receiving a blank page....thanks again for your help! Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147083 Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 Try printing something at the very start of the file, and at the very end to make sure the whole thing can load. Turn on error reporting while developing.Also, where is your database connection on the second file? Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147084 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 oh the database connection is db_connection.php i Just didnt include it in the original code....and you mentined about placing code before and at the end....what exactly would that be? ??? Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147085 Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 Whatever you want. Print 'test' at the start and end to see where it is failing. You need to include your connection in each file if you want to query the database. Use require instead of include - you hardly ever include something which is optional. Also, the code in your first file produces invalid HTML. Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147087 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 thank you so much it worked...I didnt realize that I had to open the db connection for each script...is that a good thing or abd thing to have alot of connections open or is the connection just 1 HUGE first opening and everything in it doesnt count as the 2nd, the 3rd etc...I am still learning this stuff...thanks again appreciate your help :) Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147088 Share on other sites More sharing options...
Jessica Posted December 23, 2006 Share Posted December 23, 2006 Use a persistent connection. mysql_pconnect. Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147089 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 ahh okay...awesome...I have 1 last question...regarding the script I have made...remember page2.php displayed the category...now when they click on "RINGS" the user will be brought sub-categories which I have a table called sub-categories...The table structure is as follows:sub_cat_id | sub cat name | category_idSo I want the Category ID passed from page2.php to page3.php so that way then lets say "RING" gets clicked, the user gets the Engagement Rings and Wedding Bands based on a WHERE clause...see my code below:[code]<?phpinclude('db_connect.php');?><?php$result = mysql_query("select * from subcategory WHERE category_id = '.$_GET['cid'].'");while($r=mysql_fetch_array($result)){$sub_id=$r["sub_category_id"];$subname=$r["subcategory_name"];echo "<a href='page4.php?vid=" . $vid . "&cid=". $cid . "&sub_id=". $sub_id . "'>" . $subname . "</a><br>";}?>[/code]For some reason it doesnt output anything..... Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147102 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 Actually I figured it out:[code]<?phpinclude('db_connect.php');?><?php$result = mysql_query("select * from subcategory WHERE category_id= {$_GET['cid']}");while($r=mysql_fetch_array($result)){$sub_id=$r["sub_category_id"];$subname=$r["subcategory_name"];echo "<a href='page4.php?vid=" . $vid . "&cid=". $cid . "&sub_id=". $sub_id . "'>" . $subname . "</a><br>";}?>[/code]The only problem is my damn hyperlink....I bet I goofed up and left a damn character out heheh.. Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147106 Share on other sites More sharing options...
trq Posted December 23, 2006 Share Posted December 23, 2006 There doesn't look to be anything wrong with your hyper link... what html source does it produce? Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147110 Share on other sites More sharing options...
dpabla Posted December 23, 2006 Author Share Posted December 23, 2006 actually you are right it is correct my apoligiez...but not my final question is here....[code]$result = mysql_query("select * from products WHERE subcategory_id= {$_GET['sub_id']}");[/code]Now when the customer clicks on sub-category Engagement Rings from main category RINGS the next step is to display all the engagement rings that follow the users choice:User clicks on Vendor "hearts on fire" which passes a Vendor ID = Hearts on Fire which than the customer chose the Category: Rings (so Category ID was passed) and finally, the sub cat chosen was Engagement Rings with its own sub_cat_ID that was passed as well...So how do I create a clause that performs and pulls the data "engagement rings" My products table is as such with the following fields:product_id | product name | vendor_id | category_id | subcat_id | price | description Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/31728-passing-multiple-variables/#findComment-147114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.