Connecting Tech Pros Worldwide Help | Site Map

mySQL and PHP

  #1  
Old November 11th, 2005, 04:45 PM
Khai
Guest
 
Posts: n/a
Greetings -

Right to the point:

I'm using mySQL and PHP on a webhost, and WordPress. ...and I'm very very
very new to this stuff.

Wordpress is what I'm using to make it easy for my pops to post articles.
My index.php uses some code to pull from the mySQL db (created by wordpress)
and puts the post content into a div, then p class. However, I'm noticing
that when the content contains html coding, it seems to fall out of the
class and lose it's padding. Is there some command I need to use to modify
the html code in the content when it's posted to my page?

Below is what I think is the relevant code: You can check the results at
www.meetwithkbh.com (yes, it's got a goal). If there's no html like <ul>'s
and <li>'s included in the post, it formats fine with the padding, but - if
there is, it'll drop out of the padding that i'm trying to keep.

<?php
$db = mysql_connect("localhost", "mywordpressdb", "*******"); /*no, these
aren't the real user/pass ;) */
mysql_select_db("dbwordpress",$db);
$result = mysql_query("SELECT id, post_title, post_content, post_date_gmt
FROM wp_posts ORDER BY post_date_gmt DESC Limit 0, 5",$db);
while ($myrow = mysql_fetch_row($result)) {
echo "<div class=\"post\">\n\t<p class=\"posttitle\">";
printf("%10.60s", $myrow[1]);
echo "</p>";
echo "\n<p class=\"postcontent\">";
printf("%10.400s",$myrow[2]);
echo "...<a href=\"More.php\">Read More</a></p>\n</div><br />\n";
}
mysql_close($db);
?>

Here is the css, contained in the index.php too, which is in the proper
place in the index.php:
..posttitle { font-size: 120%;
font-weight: bold;
color: white;
background: #806C59;
padding: 3px 3px 3px 1em;
margin-top:0em;
}

..postcontent { padding-left:2em;
padding-right: 2em;
text-align: justify;
}

..post {
border: 1px solid #cccccc;
line-height:1em;
}


  #2  
Old November 11th, 2005, 04:55 PM
Oli Filth
Guest
 
Posts: n/a

re: mySQL and PHP


Khai said the following on 11/11/2005 16:36:[color=blue]
> Greetings -
>
> Right to the point:
>
> I'm using mySQL and PHP on a webhost, and WordPress. ...and I'm very very
> very new to this stuff.
>
> Wordpress is what I'm using to make it easy for my pops to post articles.
> My index.php uses some code to pull from the mySQL db (created by wordpress)
> and puts the post content into a div, then p class. However, I'm noticing
> that when the content contains html coding, it seems to fall out of the
> class and lose it's padding. Is there some command I need to use to modify
> the html code in the content when it's posted to my page?
>[/color]

http://www.php.net/htmlspecialchars


--
Oli
  #3  
Old November 22nd, 2005, 12:05 AM
Toby Inkster
Guest
 
Posts: n/a

re: mySQL and PHP


Oli Filth wrote:
[color=blue]
> http://www.php.net/htmlspecialchars[/color]

or perhaps: http://uk2.php.net/manual/en/function.strip-tags.php

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

  #4  
Old November 22nd, 2005, 12:05 AM
Raqueeb Hassan
Guest
 
Posts: n/a

re: mySQL and PHP


>> http://www.php.net/htmlspecialchars
[color=blue]
> or perhaps: http://uk2.php.net/manual/en/function.strip-tags.php[/color]

Perfect links! Here is an example from man pages ....


<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href='test'&gt;Test&lt;/a&gt;
?>


--
Raqueeb Hassan
Bangladesh

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Price List for MOM & POP when choosing between MySql/PHP and .NET nospam answers 14 November 15th, 2005 12:04 PM
Passing values from JavaScript into MySQL/PHP RootShell answers 2 July 23rd, 2005 01:27 PM
Price List for MOM & POP when choosing between MySql/PHP and .NET nospam answers 13 July 21st, 2005 09:46 AM
FW: A final Windows MySQL PHP plea Gary Broughton answers 0 July 20th, 2005 12:08 AM
FW: A final Windows MySQL PHP plea Gary Broughton answers 0 July 20th, 2005 12:08 AM