Jump to content

passing multiple variables?


dpabla

Recommended Posts

here is an example site of what I am doing:

www.leohamel.com/test/jewelry

The 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.php

Here is my code for page1.php

[code]<?php
include('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!
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 :)
Link to comment
Share on other sites

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_id

So 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]<?php
include('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.....
Link to comment
Share on other sites

Actually I figured it out:

[code]<?php
include('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..
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.