I am trying to create a news page for a pharma website.
I have created a news article "creation" page that allows a user to input information such as author, description, and body.
The code looks like this.
<html>
<body>
<style>
textarea
{
resize: none;
}
</style>
<form action="foo.php" method="post">
<label for="textarea">Title:</label>
<p></p>
<textarea rows="1" cols="100" name="title"></textarea>
<br></br>
<label for="textarea">Author:</label>
<p></p>
<textarea rows="1" cols="100" name="author"></textarea>
<br></br>
<label for="textarea">Description:</label>
<p></p>
<textarea rows="15" cols="100" name="desc"></textarea>
<br></br>
<label for="textarea">Body:</label>
<p></p>
<textarea rows="15" cols="100" name="body"></textarea>
<br></br>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
That information gets sent to foo.php, and I would like foo.php to dynamically create a div with the title, author, publish date, and description displayed within. This div would then have a "Read More" button that would display the actual article or "body" in this case.
I would then like to insert this div into a seperate html page. So in other words, every time the user creating a new article clicks the submit button, the information is processed, added to a div element and then that div is inserted into another html page.
Is there any way to do this, or some sample news/articles tutorial that explains how to do this? I've been searching for hours and there seems to be nothing on this particular topic. I've also tried something along the lines of this, but this has gotten me nowhere, and after 3+ days of trying to figure this out, Im ready to gouge my eyes out.
<script>
<?php
foreach (glob("*.txt") as $filename)
{
$lines_array = file($filename);
$search_string_title = "Article_title";
$search_string_published = "Published";
$search_string_author = "Author";
$search_string_desc = "Description";
$search_string_body = "Body";
foreach($lines_array as $line)
{
if(strpos($line, $search_string_title) !== false)
{
list(,$title_str) = explode(":", $line);
}
if(strpos($line, $search_string_published) !== false)
{
list(,$published_str) = explode(":", $line);
}
if(strpos($line, $search_string_author) !== false)
{
list(,$author_str) = explode(":", $line);
}
if(strpos($line, $search_string_desc) !== false)
{
list(,$desc_str) = explode(":", $line);
}
if(strpos($line, $search_string_body) !== false)
{
list(,$body_str) = explode(":", $line);
}
}
$article_title = $title_str;
$published = $published_str;
$author = $author_str;
$desc = $desc_str;
$body = $body_str;
$news_content= array($article_title, $published, $author, $desc, $body);
}
?>
var news = <?php echo json_encode($news_content) ?>;
var title = news[0];
var published = news[1];
var author = news[2];
var desc = news[3];
var body = news[4];
var div = document.createElement("div");
div.style.width = "600px";
div.style.height = "600px";
div.style.background = "red";
div.style.color = "white";
var sHTML = '<div style="text-align:center; padding:15px; font-weight:bold;">' + title + "<br />" + "<br />" + "Published: " + published + "<br />" + "Author: " + author + "<br />" + "<br />" + desc + </div>';
div.innerHTML = sHTML;
div1.appendChild(div);
</script>
What you are trying to do sounds a lot like MVC
The way I would do it is make a page like the one you're describing and when I'm done entering the info, I'd send the data to a PHP script to put my information in a database(like MySQL).
On the page where you want the divs to appear I'd then just loop through my database articles rows and make my php echo the info you want in those divs.
Sounds like you need a database!
You would store the information from the page you posted in to the database. Then, foo.php would load this information from the database.
Look in to MySQL with PHP. The two play nicely with each other. If you are unfamiliar with databases in general, I would recommend following some Microsoft Access database tutorials. Access allows you to easily visualize how data is saved in a database.
I would consider taking that information and putting it into a database, and on the other page, have it pull records from the database table and populate divs that way.