Jump to content


Photo

newbie Q: Need to make and display link + page in Database


  • Please log in to reply
24 replies to this topic

#1 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 12 July 2006 - 08:33 AM

Hello everybody,

I'm a noob with PHP but slowly im workin my way around. I have a problem though. I need to have a form where you can create a new link on a page that links to another page with text that you also have to input in the form. I also need a delete function.
I cant find it on the internet and tutorials are not helping me.
Can anyone help me out, guide me trhough the process or send me to a good URL with a bit of the code?

Thanks in advance

T.bo

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 08:36 AM

sorry i dont understand wat u mean, got any examples, or can u explain a bit more.

might be me, as im half asleep.. lol

#3 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 12 July 2006 - 08:38 AM

Read the FAQ, find $_GET

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#4 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 12 July 2006 - 08:42 AM

Well im makeing this site http://www.euroclinix.com
When you go to "behandelingen" (wich means treatments) you see all the possible links to treatments above. (botox, ...)
But now I want to make it possible to make new treatments with their new page and display the new link next to the other treatments.

Hope this helps cuz I really need this one.

greetz

#5 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 09:30 AM

Its up to you, you could try looking around for a pre-built CMS (Content management system) or try to make your own smaller version, either way your going to need a database.

you are basically going to have a database table containing a treatment title, the contents of the page about the treatment and any other info.

You would then have a page that would pull all the titles from a database and show a link to them.

Alternatively, you could investigate using file uploading if you are wanting people to upload their own html files, and then you would probably only need to store the url of the file and the title in a database.

However you do it, its not going to be all that simple, perhaps it might be better trying out some other php tutorials to get a better understanding of it first.

#6 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 12 July 2006 - 10:32 AM

Thank u for the reply!!

Im one step further now.
But I have problem with making the correct links, it should be something like this <a href="index.php?content=treatment&id="$id">
That should make a link but how can I display the content that matches the id when the link is clicked?

#7 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 10:38 AM

$content = $_GET[content];
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM `table` WHERE `content`='$content' and `id`='$id'");
then grab the information you need and display it.


#8 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 12 July 2006 - 10:50 AM

Damn,
its still kinda hard for me...

If I grab the info like u said. Put it in the variables...ok

But then I dont know how I can make the link work
<a href="?id=$id>link to treatment<a>
when I click the link the content should be $content.
How can i do that?


#9 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 10:52 AM

Do you already have a database with the content for each treatment each with a corresponding id?

#10 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 13 July 2006 - 08:55 AM

Yes exactly , so its just giving problems for a correct output...

#11 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 13 July 2006 - 09:09 AM

Well you have to query the database to get the IDs that you want e.g.
<?
$sql = mysql_query("SELECT * FROM `yourtable'");
while($row = mysql_fetch_assoc($sql))
{
$title = $row['titlefield'];
$id = $row['idfield'];
echo "<a href='page.php?id=$id'>$title</a>";
}
?>

And then on "page.php":

<?
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'");
then grab the information you need and display it.
?>

You will have to modify the table and field names.

#12 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 13 July 2006 - 12:17 PM

thanks Im gonna try it later
Hope it works

grtz

#13 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 13 July 2006 - 05:29 PM

Damn it didn't work.

The variables stay empty I think.
This is the table :
CREATE TABLE `yourtable` (
  `idfield` int(11) NOT NULL auto_increment,
  `titlefield` varchar(250) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY  (`idfield`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

The table already has inputs...

This is the php :
Page with the links :
<?
include('dbconnect.php');
$sql = mysql_query("SELECT * FROM `yourtable'");
while($row = mysql_fetch_assoc($sql))
{
$title = $row['titlefield'];
$id = $row['idfield'];
echo "<a href='page.php?id=$id'>$title</a>";
}
?>

Page.php  :
<?
include('dbconnect.php');
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'");
$content = $_GET[content];
echo "$content";
?>
I probably made a mistake with page.php but the page with the links should work a,d it does not...
Dbconnect is correct though

#14 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 14 July 2006 - 10:20 AM

Can anyone help me out?

I really need this one.

Greetz and thanks in advance.

#15 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 11:02 AM

isn't content supposed to come from the database? if so:

$content = mysql_result($sql,'0',"content");
echo "$content";

#16 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 14 July 2006 - 11:46 AM

Hmm still doesnt work..

Is it possible that there is a problem with the ", ' and ` tags?


#17 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 11:47 AM

Add an or die statement:

$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'") or die(mysql_error());
$content = $_GET[content];
echo "$content";

#18 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 14 July 2006 - 12:22 PM

Ok now I get :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and `idfield`='1'' at line 1


#19 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 14 July 2006 - 12:26 PM

Ok I GOT IT  ;D

<?
include('dbconnect.php');
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM yourtable WHERE idfield='$id'") or die(mysql_error());
$r=mysql_fetch_array($sql);
$content = mysql_result($sql,'0',"content");
echo "$content";
?>


Works perfect. Thanks for everything

#20 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 12:27 PM

You beat me too it. Glad to help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users