Hi everyone!

Have a few questions I hope someone may be able to help me with, because I'm really stucked here.. And sorry if I'm not explaining myself very good, because my english is not that good.

Well..

I am trying to build my own blog with like a Content Management System with an index.php site and a about.php site.. - But look away from the about.php, what I need help for is the index.php site..

What I have made so far is this script that makes a new table for every time I want to make a new post:

<?php
		// Connects to your Database
		mysql_connect("localhost", "something", "something") or die(mysql_error());
		mysql_select_db("something") or die(mysql_error());
		
		$tabelnavn = $_POST['tabelnavn'];

		// Create a MySQL table in the selected database
		mysql_query("CREATE TABLE ".$tabelnavn." (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), content LONGTEXT, name VARCHAR(100), email VARCHAR(100), url VARCHAR(250), post_date DATETIME)")
		or die(mysql_error());  
		
		echo "<strong>$tabelnavn</strong> has been made!";
			
?>

- and it works just fine.. So now I have created a table and I can now start putting in the content, all good..

Here's my question:
How on earth can I make it generate a link showing on the index.php site that this is the newest post and when you click on it you will be directed to the post and read the full post? I dont really know how to explain properly, so here's a picture of what I want to do similar (this screen print has been taken from nettuts.com):

http://img218.imageshack.us/img218/4562/helpx.jpg

So when I make a new table, puts in the content and all, I want the post to display on my index.php site a when you click on it you will be directed to the full post..

Hope there will be some help out there, Im really really stucked here!

Thanks in advance
Brian

Why are you making a new table for each post? I think you don't understand how a database works.

You might want to research that a bit before trying to create a blog/cms.

When I use the SELECT statement it will blow out all that is in the table and I want seperate sites to be shown, not all full posts on one site..

They have WHERE clause you can add to that select statement to help refine the data selected from the table.

Where Clause

You will most likely have to restructure your database to work as its suppose to.

Also, in the code you posted, you have sql injection and xss holes. You will need to research these as well so your blog won't get hacked.

Thanks, I'm gonna have a look at that..
But I dont think that that was my kinda of problem..

Hope to get some more answers..

Then whats the problem? I gave a solution based on what you posted. Maybe you could be a little clearer.

Member Avatar for diafol

If your DB design is good from the start, you will almost never need to create a new table dynamically.

Like KK mentions, do some research first. Here's a hint

TABLES required:

1) articles
2) registered_users
3) comments

You shouldn't need more than those 3 to create a fully functional simple blog-and-comment system.

I'm sorry but I dont know how to be explain better..

As keith said I will ned to use the SELECT WHERE, yes and I'm looking at it right now, and I understand with the tables that I dont have to post new tables all the time, and I must be hounest it seemed wrong for me aswell thats why I came here..

But lets say I make a new post, and it is inserted to my table in MySQL how do I then push out the "teaser" (to the index.php) that is clickable so that you move on to the full post, how do I make it generate a new link under my Categories sidebar and a new index.php/newpost1 and when I post a new post it makes index.php/newpost2 for me..

Im sorry I guess it's hard to understand, buts it only one thing.. And I know that I must to a lot of research to be better on how to do this.. I just wanted to ask here first..

Im glad for your answers though!

I have made my database completely different, with only 2 tables - I get it now :)

I think what I was trying to explain last time is that when I post a new site I want it to make a new itself - make a site that doesnt exists you know, something similar to this (one of my friends hwo told me to do this)

<?php 
$side = $_REQUEST["side"];

if ($site == "test")
{ 
 echo "This is content";
}

?>

But that doesnt seem to work either.. - But I hope that gave someone af feeling of what I'm trying to do - im sooo stucked!

Some help around here?

Thanks
Brian

You want to create a php framework which creates a new sites. Did you heard about joomla and drupal?

Thanks for answering, but it isnt a framework I'm looking for.
But, yes I'm already familiar with Joomla and Drupal.

Why don't you have a site_id column on your table and assign each site an id?

Then you can just do

$q = @mysql_query("SELECT * FROM article WHERE site_id = $site_id ORDER BY article_date DESC LIMIT 1");

so each one of your sites has a $site_id variable that is unique to the site in question. That would also just bring back the latest one.

Then you just need to manipulate it to show just the first 200 characters or so as a link

$r = @mysql_fetch_array($q);
echo "<a href=\"article.php?id=".$r['article_id]."\">".substr($r['article_text'],0,200)."&nbsp;...read more<a/>";

The above is of course very basic as I don't know your table and column names and there is no validation here on input parameters or what comes out of your db.

Don't take this the wrong way either but it really looks like you should look at some more beginners tutorials and examples before trying to do this.

Yes finally someone hwo gets it, thanks alot man!
- I think it's something like that I'm looking for - I will get back at it tomorrow and check it out..

Yes, I'm still in the process of learning PHP and MySQL - and like I have said before, that's why I came here to get an advice if someone had one..

But hey, thanks Tommy!

No problem. I was just saying try to get used to a single table and working from that first. That's how I started out real basic. By all means ask questions here and get help, but really try to follow some tutorials starting at the basics making sure you are understanding them instead of copying and pasting.

It can seem tough at first which is where forums come in help but eventually it will click. Just have a real go at understanding what each line of code does

good luck

Yeah cool..

Dont get me wrong - the tables was a complete "dummy-thought" from my side, but I'm not that stupid at PHP though and I'm certanly not copy and pasting all.. I have already made a bunch of stuff, I just had a problem here I couldnt pass. I've made this comment system already for the part of the little "blog" Im making http://webeliten.dk/tjek/ and done alot more..

I just had a problem here, and Im still not good with variables and stuff :/

But thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.