csudhoff Posted November 20, 2007 Share Posted November 20, 2007 How would I go about creating links. Should I use arrays? below is kid of what i am looking to do Catagories - Fruit = 1 - Meat = 2 - Vegs = 3 Sub catagories - Fruit - Strawberries =101 - Grapes = 102 the link would appear - http://www.websiteurl.com/subcat=101 I am not sure if this makes sense and i am in the process of learning the terminology. Thanks! Quote Link to comment Share on other sites More sharing options...
revraz Posted November 20, 2007 Share Posted November 20, 2007 How are you storing the catagories? Hard coding or in a flat file/database? Quote Link to comment Share on other sites More sharing options...
csudhoff Posted November 20, 2007 Author Share Posted November 20, 2007 thats part of what i need to know. can i include this in another php file or will i need to create a mysql db with 2 tables. 1 called cat and one sub cat? thanks for the prompt reply Quote Link to comment Share on other sites More sharing options...
trq Posted November 20, 2007 Share Posted November 20, 2007 You don't need two tables. One shall suffice. CREATE TABLE products ( id PRIMARY KEY AUTO INCRIMENT, parentid, title VARCHAR(80) ); Now insert your products.... INSERT INTO products (parentid,title) VALUES (0,'Fruit'); INSERT INTO products (parentid,title) VALUES (0,'Meat'); INSERT INTO products (parentid,title) VALUES (0,'Veg'); INSERT INTO products (parentid,title) VALUES (1,'Strawberries'); INSERT INTO products (parentid,title) VALUES (1,'Grapes'); See how the parentid relates Strawberries and Grapes to Fruit? Quote Link to comment Share on other sites More sharing options...
csudhoff Posted November 20, 2007 Author Share Posted November 20, 2007 ok I think i am getting this. What would be the syntax for my links on my menu system then? Quote Link to comment Share on other sites More sharing options...
DyslexicDog Posted November 20, 2007 Share Posted November 20, 2007 thats part of what i need to know. can i include this in another php file or will i need to create a mysql db with 2 tables. 1 called cat and one sub cat? thanks for the prompt reply You can do it either way. If you use a database you can easily update it later. The easiest way I've found to create links is with an associative array. <?php //First we create the array $links = array('link title' => 'link.com/location' , 'link title 2' => 'link.com/location'); //if I want to add more links later it's pretty easy todo, you can even change existing links. $links['link title3'] = 'foobar.com'; $links['link title'] = 'link.com/location17'; //then after the array is setup the way we want we run it through a foreach loop to create the html links foreach($links as $title => $href){ echo '<a href="$href">$title</a>': } ?> WARNING: I didn't test this code it may have some errors. Quote Link to comment Share on other sites More sharing options...
csudhoff Posted November 21, 2007 Author Share Posted November 21, 2007 Thanks for all of the help! this is what i am reffering to: <a href="/myspace-layouts/cat.php?id=10">Animals</a> <a href="/myspace-layouts/cat.php?id=9">Animated Backgrounds</a> <a href="/myspace-layouts/cat.php?id=19">Anime</a> <a href="/myspace-layouts/cat.php?id=38">Butterflies</a> <a href="/myspace-layouts/cat.php?id=28">Cars/Vehicles</a> this site does this exactly. in this example woudl i have a cat.php file and reference "animails = 10... etc... sorry i don tmean to be spoon fead, i am trying my best to learn on my own. Quote Link to comment Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 Yes, the cat.php file would simply query the database for data relating to the id passed to it in $_GET['id']. Quote Link to comment Share on other sites More sharing options...
csudhoff Posted November 21, 2007 Author Share Posted November 21, 2007 Yes, the cat.php file would simply query the database for data relating to the id passed to it in $_GET['id']. ok kow of any good tutorials that i can look @? I am a noob w/ php. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 21, 2007 Share Posted November 21, 2007 create your database with mysql or mysql based software like phpMyAdmin and then use the code below as a reference on how to display content in your pages based on "id". <?php // Connect To Database mysql_connect("localhost","username","password"); // Select Database mysql_select_db("vehicleList"); // Query Database $myresults = mysql_query("select * from dataTableNameHere where idFieldNameHere='$id'"); while ($myrow=mysql_fetch_array($myresults)) { // Declare Your Variables $myvariable1=$myrow["SomeFieldNameHere"]; // Design Your Content & Add Your Variables To Where Ever You Want Them To Display At echo "<div>\n"; echo "$myrow\n"; echo "<div>\n"; } ?> Here is a pretty decent mysql tutorial: http://www.tizag.com/mysqlTutorial/mysqldatabase.php Quote Link to comment 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.