Forum Moderators: open

Message Too Old, No Replies

Table/Syntax - Lots of Issues

         

Krossinc

7:27 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



I'm about as green as you can be when it comes to PHP.

Here is the basic gist of what I am trying to produce. I have a site which contains 10 news articles listed in 'most recent first' format. The site will be consistently updated by another who is submitting articles 2-3 a day. Here's where my questions begin.

One, I understand that he can fill in a form and that assigned value can be transferred eventually to the database.

Okay, since part of the submission process redirects you to another page, i.e form action="newpage.php" method="post" what exactly needs to be on the page with the textbox? Does it need to connect to the mySQL server there?

Also, for the next page, the one it goes to. Right now, I am just trying to assign the value of the form submission to fit in the 12th spot of my table(named articles), named 'newa' . I thought I had the basic idea, but on a query of the article gave me a syntax error of 1064.

Here is my basic coding I have implemented so far. Table is called articles

<?php

$hostname="server";
$username="username";
$password="pw";
$dbname="database";

$connectID=mysql_connect($hostname,$username, $password)
or die("Cannot Connect to Server");

mysql_select_db($dbname);

$newpost=$_POST['newsa'];

$query = "INSERT INTO articles(newa) VALUES ('$newpost')";
mysql_query($query);

mysql_close($connectID);
?>

While I'm here, let me check on this also. My Table looks like this
id
a1
a2
a3
a4
a5
a6
a7
a8
a9
a10
newa

Whenever the text box is filled in and submitted. I want the value of the box to assign to newa. Then I went a10 to take on the value of a9, a9 to take on the value of a8, etc... with a1 taking on newa. Would this be the best way to do that? Or at least...work?

mysql_query('INSERT into articles(a10, a9, a8, a7, a6, a5, a4, a3, a2, a1) VALUES (a9, a8, a7, a6, a5, a4, a3, a2, a1, newa);

Let me know if I'm even in the ball park. Lots of stuff here, again I'm very grateful.

Krossinc

1:51 am on Sep 17, 2007 (gmt 0)

10+ Year Member



Any one? I really need some help with this, haha.

coopster

6:58 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi Krossinc and welcome to WebmasterWorld.

How about just leaving articles in the database with a DATETIME created field associated to them? That way you can always query the database for the latest articles by date?

mattur

7:05 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As coopster points out, the way to do this is store the articles as multiple records, not columns in one record. So your table would be something like:

ArticleID
ArticleTitle
ArticleBody
ArticleDate
...etc

Krossinc

2:09 am on Sep 19, 2007 (gmt 0)

10+ Year Member



Thank ya kindly, that is the smart thing to do. A question I need help with also is - is how do you make a single area of a table output.

mattur

1:13 pm on Sep 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you mean selecting some fields in a record? The example below gets the article title and body for article with id 1 (assuming that's how you've named your fields/table).

SELECT ArticleTitle, ArticleBody 
FROM tblArticle
WHERE ArticleID=1;

Or for selecting all fields from the ten most recent records:

SELECT * 
FROM tblArticle
ORDER BY ArticleDate DESC
LIMIT 10;

Assuming field names and table name as above, and you're using MySql. HTH