Jump to content

echo out by id


dazz_club

Recommended Posts

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

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

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

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

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
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.