shyish Posted August 16, 2009 Share Posted August 16, 2009 Ok I have a MySQL database of all the websites and templates I make to put on a portfolio site. I was wondering how to make a database so that each website design has a seperate link, without me having to make a page for each one... so it would display as portfolio.php?0001 or whatever? Currently the database just contains ID, thumbnail, large preview, demo link, colours, information and what it's made in (flash, HTML CSS etc.) My PHP is really rusty, so Im not sure what to do to achieve this... Currently my intention first is to have a list of all the sites displaying their thumbnail, ID, what used, colours in a grid-style-list and to try and add a search feature (not sure how to do that either yet) Thanks in advance ~Shyish. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 16, 2009 Share Posted August 16, 2009 Is this what you mean? $id = $_GET['id']; switch($id){ case 1: //Show detailed info about site with id = 1; break; case 2: //Show detailed info about site with id = 2; break; ... default: $query = "SELECT * FROM sites"; $result = mysql_query($query); while($sites = mysql_fetch_array($result)){ echo "<a href='./sites.php?id='" . $sites['id'] . "'>" . $sites['thumbnail'] . "</a>"; } break; } Quote Link to comment Share on other sites More sharing options...
shyish Posted August 16, 2009 Author Share Posted August 16, 2009 ... cough... Umm possibly :L Pretty much I just want it so I dont need to make a new page for every website I add, because with that I might aswell not use PHP.. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 16, 2009 Share Posted August 16, 2009 Okay I see, Do you know what this(the code I wrote above) does? (if not, you really should learn the basics of php,) Quote Link to comment Share on other sites More sharing options...
shyish Posted August 16, 2009 Author Share Posted August 16, 2009 I learn by example. And I kind of do, I know what parts of it mean/do etc. but other parts Im yet to use. Quote Link to comment Share on other sites More sharing options...
shyish Posted August 16, 2009 Author Share Posted August 16, 2009 damn the lack of an edit button I can see... The main issue is I have no idea where I should be putting that code to use it... Quote Link to comment Share on other sites More sharing options...
shyish Posted August 16, 2009 Author Share Posted August 16, 2009 Bumping so it doesn't fall onto the next page... Ok well I've got the list done and it works great with all the JS etc, I just need the pages done now really, so if someone can help me I would love them for ever and give them 50% of the first profit I make thanks Quote Link to comment Share on other sites More sharing options...
peter_anderson Posted August 16, 2009 Share Posted August 16, 2009 You could always use: <?php //load config require_once("config.php"); //get ID $site = $_GET['siteid']; //connect to DB mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); //load $result = mysql_query("SELECT * FROM portfolio WHERE id=$site"); if(mysql_num_rows($query) ==0) { header("Location: /page/404"); exit; } //code to display content ?> Quote Link to comment Share on other sites More sharing options...
shyish Posted August 16, 2009 Author Share Posted August 16, 2009 Thanks but I've tried simply using these scripts but they aren't really helping me =( Please if someone can actually explain to me what I need to do, I will be so happy. Quote Link to comment Share on other sites More sharing options...
shyish Posted August 17, 2009 Author Share Posted August 17, 2009 Ok I've tried flicking through numerous PHP guides and googling and asking on other sites still nothing... Can someone help Also bumping before this falls into the pit of PAGE 2! Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 17, 2009 Share Posted August 17, 2009 I would suggest you learn the W3Schools Tutorial Quote Link to comment Share on other sites More sharing options...
peter_anderson Posted August 17, 2009 Share Posted August 17, 2009 Thanks but I've tried simply using these scripts but they aren't really helping me =( Please if someone can actually explain to me what I need to do, I will be so happy. Here's a little more for mine. For the DB, you need: CREATE TABLE sites( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), `title` VARCHAR(30), `link` VARCHAR(30), `description` VARCHAR(3000)) For the display page, you need: <?php //DB info $host = 'localhost'; $user = 'user'; $pass = 'pass'; $db = 'db'; //get ID $site = $_GET['siteid']; //connect to DB mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); //load $query = mysql_query("SELECT * FROM portfolio WHERE id=$site"); //if there is no such site, if(mysql_num_rows($query) ==0) { //go to 404 header("Location: /page/404"); exit; } //for content $row = mysql_fetch_array($query); //display the site name echo '<p>Site Name: '.$row['title'].' </p>'; //display the link echo '<a href="'.$row['link'].'" target="_blank">Click here to visit the site</a></p>'; //display the description echo '<p>'.$row['description'].'</p>'; ?> 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.