Jump to content

Display DB of sites


shyish

Recommended Posts

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.

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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 :P

 

thanks

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

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>';
?>

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.