dazz_club Posted February 20, 2008 Share Posted February 20, 2008 Hi there guys, I have got a table called "press_coverage" with fields such has title, content, image, date. When its complete it would look similar to a blog where by the latest press coverage moves to the top with the old press coverage underneath. I have got it to work by creating a seperate function so it can pull out each tabe data seperate. So i have a funciton for the headers, content, etc. <?php ///This pulls out the header title function header_title($id) { $query = mysql_query("SELECT header FROM `press_coverage` WHERE `id` = '1'") or die(mysql_error()); $row = mysql_fetch_array($query); return $row['header']; } ///This pulls out the content function get_content($id) { $query = mysql_query("SELECT content FROM `press_coverage` WHERE `id` = '1'") or die(mysql_error()); $row = mysql_fetch_array($query); return $row['content']; } ?> There are more press coverage (currently 2) within the database with their own id. So what i would like to happen is for my function to retireve all the data by id and then echo it out with in a list or similar to a blog works. If anyone can point me in the right direction it would help. Cheers Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/ Share on other sites More sharing options...
dazz_club Posted February 20, 2008 Author Share Posted February 20, 2008 hi guys and girls, ok I have now managed to do this I am using this code; <?php $query = "SELECT `header` , `content` , `publication` , `month_of_article` , `year_of_article` FROM press_coverage ORDER BY year_of_article DESC" ; If ($r = mysql_query ($query)) { //sending the query to the mySQL server While ($row = mysql_fetch_array($r)) { //inputs the data into the table $header = $row['header']; $content = $row['content']; $publication = $row['publication']; $month_of_article = $row['month_of_article']; $year_of_article = $row['year_of_article']; ?> Now here comes my question. The content field contains the article, how would i break it up so they appear as nice paragraphs. Rather then having a blcok of informatted text? And then echo the right info out. Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-471798 Share on other sites More sharing options...
suttercain Posted February 20, 2008 Share Posted February 20, 2008 Is your content formated in html or is it just plain text? Also, if it's not in html do you know if it contains line breaks \n ? Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-471806 Share on other sites More sharing options...
aebstract Posted February 20, 2008 Share Posted February 20, 2008 <?php $query = "SELECT `header` , `content` , `publication` , `month_of_article` , `year_of_article` FROM press_coverage ORDER BY year_of_article DESC" ; If ($r = mysql_query ($query)) { //sending the query to the mySQL server While ($row = mysql_fetch_array($r)) { //inputs the data into the table $header = $row['header']; $content = $row['content']; $publication = $row['publication']; $month_of_article = $row['month_of_article']; $year_of_article = $row['year_of_article']; echo "<p>$header, $content, $publication, $blablabla whatever wahtever</p>"; ?> So basically, what I am saying is: however you are outputting your content, wrap it in a paragraph tag, or a div or something and style it however you need. Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-471820 Share on other sites More sharing options...
dazz_club Posted February 20, 2008 Author Share Posted February 20, 2008 Hi guys, the content is wrapped in a div with styling such color, font-weight. some how i need to break it up so it appears in paragraphs. I dont know if theres any other style that can do this using css. I have posted the entire code below for you to have a bigger picture and for a better understanding. <body> <div id="conatiner"> <div id="holder"> <?php $query = "SELECT `header` , `content` , `publication` , `month_of_article` , `year_of_article` FROM press_coverage ORDER BY year_of_article DESC" ; If ($r = mysql_query ($query)) { //sending the query to the mySQL server While ($row = mysql_fetch_array($r)) { //inputs the data into the table $header = $row['header']; $content = $row['content']; $publication = $row['publication']; $month_of_article = $row['month_of_article']; $year_of_article = $row['year_of_article']; ?> <div id="header" class="header"> <?php echo $header; ?> </div> <div id="content"> <?php echo $content; ?> <div id="image"> image here </div> </div> <ul id="info"style="list-style-type:none;padding:0px;margin:0px;"> <li>Released in: <span style="font-weight:bold;"><?php echo $month_of_article; ?></span></li> <li style="color:black;">|</li> <li>Name of publication: <span style="font-weight:bold;"><?php echo $publication; ?></span></li> <li style="color:black;">|</li> <li>Year: <span style="font-weight:bold;"><?php echo $year_of_article; ?></span></li> <li style="color:black;">|</li> <li><a href="#" >original.pdf</a></li> </ul> <div style="margin-top:30px;height:10px;width:%;border-bottom:1px solid black;"> <?php } } else { //query did not run. die (); } mysql_close(); ?> </div> </div> </div> </body> Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-471845 Share on other sites More sharing options...
suttercain Posted February 20, 2008 Share Posted February 20, 2008 Hi Dazz, Can you answer my question above so I can assist? Thanks. Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-471848 Share on other sites More sharing options...
dazz_club Posted February 20, 2008 Author Share Posted February 20, 2008 Hi suttercain, It is styled, i have wrapped the php that echo's the content with a div. i.e <div id="content"> <?php echo $content; ?> <div id="image"> image here </div> </div> This sets the style for the overall text on the page. body {margin:5px;background-color: #e8e8dc;color: black;text-align:center;padding:0px;font-family:tahoma;font-size:10pt;} The div id="content" style is #content{height:auto;width:624px;text-align:left;border-bottom:1px dashed black;padding:2px;} I have used no line break within the php code which is <?php echo $content; ?> The above code echo's out the content Hope that helps. Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-471938 Share on other sites More sharing options...
dazz_club Posted February 21, 2008 Author Share Posted February 21, 2008 ok just out of curisosity i typed in html code for break, <br /> , into my phpmyadmin. I then checked the site and it worked. So I am all sorted. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/92075-echo-out-by-id/#findComment-472780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.