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
https://forums.phpfreaks.com/topic/170503-display-db-of-sites/
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
https://forums.phpfreaks.com/topic/170503-display-db-of-sites/#findComment-899416
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
https://forums.phpfreaks.com/topic/170503-display-db-of-sites/#findComment-899564
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
https://forums.phpfreaks.com/topic/170503-display-db-of-sites/#findComment-899587
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
https://forums.phpfreaks.com/topic/170503-display-db-of-sites/#findComment-899918
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.