Jump to content

Recommended Posts

blog.php

 

<?php

$title = "Blog";

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("blog", $connect) or die(mysql_error());

function bbcode($string)
{


    if ($string) {


        $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]',
            '

', '', '', ':P');

 

 

        $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>',

            '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">',

            '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />');

 

 

        $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string);

 

 

        return $new_string_2;

 

 

    }

}

 

echo "<h1>Blog</h1>\n";

 

$query = mysql_query("SELECT * FROM blog");

 

if (mysql_num_rows($query) == 0) {

    echo "<hr />There are no posts yet, make the first in the admin section!\n";

} else {

    while ($row = mysql_fetch_assoc($query)) {

    echo "<hr />";

$id = $row['id'];

    $title2 = $row['title'];

    $name = $row['name'];

    $email = $row['email'];

        $post = $row['post'];

        $date = $row['date'];

        $time = $row['time'];       

           

        echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(substr($post,0,201), wordwrap($post, 118, "<br />", true))));

if(strlen($post) > 201){

        echo "...<a href='./index.php?p=blog&p=post&id='" . $id . "'>Read More</a></td></tr></table>\n";

        }else{

        echo "</td></tr></table>\n";

        }     

    }

}

 

echo "<hr />\n";

 

echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n";

 

?>[/code]

 

I also need it to only select the post from the id that it is on.

 

post.php

 

<?php

$title = "View Post:" . $title2;

function bbcode($string)
{


    if ($string) {


        $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]',
            '

', '', '', ':P');

 

 

        $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>',

            '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">',

            '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />');

 

 

        $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string);

 

 

        return $new_string_2;

 

 

    }

}

 

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("blog", $connect) or die(mysql_error());

 

$q = mysql_query("SELECT * FROM blog");

 

while($row = mysql_fetch_assoc($q)){

  $title2 = $row['title'];

  $name = $row['name'];

  $email = $row['email'];

    $post = $row['post'];

    $date = $row['date'];

    $time = $row['time']; 

   

echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(wordwrap($post, 118, "<br />", true))));

}

 

 

?>[/code]

 

My main problems are:

 

  • The id comes up with - http://localhost/dynamic web page/index.php?p=blog&p=post&id=
  • The post.php shows both posts that are entered in the database

it is because here



echo "...<a href='./index.php?p=blog&p=post&id='" . $id . "'>Read More</a></td></tr></table>\n";

 

you are closing your href attribute with the following

href='./index.php?p=blog&p=post&id='

 

you dont need to surround get values with quotes.

 

echo "...<a href='./index.php?p=blog&p=post&id=" . $id . ">Read More</a></td></tr></table>\n";

 

for the record, not many people care if you change what programming language you use.

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.