Jump to content

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


t.bo

Recommended Posts

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
Link to comment
Share on other sites

Well im makeing this site [url=http://www.euroclinix.com]http://www.euroclinix.com[/url]
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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

Well you have to query the database to get the IDs that you want e.g.
[code]
<?
$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>";
}
?>
[/code]

And then on "page.php":

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

You will have to modify the table and field names.
Link to comment
Share on other sites

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 :
[code]<?
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>";
}
?>
[/code]

Page.php  :
[code]
<?
include('dbconnect.php');
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'");
$content = $_GET[content];
echo "$content";
?>
[/code]
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
Link to comment
Share on other sites

Ok I GOT IT  ;D

[code]<?
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";
?>

[/code]

Works perfect. Thanks for everything
Link to comment
Share on other sites

My input and output code works perfect... But now the DELETE code :

[code]<?
include('dbconnect.php');

if(!isset($cmd))
{

  $result = mysql_query("select * from yourtable") or die(mysql_error());
 

  while($r=mysql_fetch_array($result))
  {

      $title=$r["titlefield"];
      $id=$r["idfield"];
   

      echo "<a href='treatedit.php?cmd=delete&idfield=$id'>$title - Delete</a>";
      echo "<br>";
    }
}
?>
<?
if($cmd=="delete")
{
    $sql = "DELETE FROM yourtable WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "treat deleted";
}
?>
[/code]

It displays the correct links and gives the correct output (treat deleted). But it does not actually delete :-s

Can U help once again :-)

Thanks in advance
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.