Page 1 of 1
Adding edit tables
Posted: Mon Apr 21, 2003 10:00 pm
by kkurkowski
I made this news script for my website and now I want to add in a posts section. This section will have everything that, that user has post and you can select them and delete them or edit them. I am totally lost on how it is going to know what post is from what user and just display that post instead of everyones. Anyone think they can help me, thanks!!
Posted: Mon Apr 21, 2003 10:54 pm
by McGruff
I think you'll need to add a field to the submissions form to gather names - as well as something to make sure each name is unique: ie some kind of registration, login & authentication system (you just might have several submitters called Cecil or Marigold).
Once you can identify submitters, one option is to store links to their articles in an "authors" table. A single field could do this if you add ID's for each news article separated by a space / underscore or whatever; later, explode() can get an array of article IDs for a single author.
Or, you could store names along with the article content in your "news items" table - whichever makes more sense with your setup.
Posted: Mon Apr 21, 2003 11:01 pm
by kkurkowski
I do have a login system on it too. People can signup and add news. Now I am just adding the posts section now. I have all the post in a table called news_news, so I could just use the explode() command and it will gather the user's information that is logged in??
Posted: Mon Apr 21, 2003 11:03 pm
by kkurkowski
By the way, I am using MySQL to do this too.
Posted: Mon Apr 21, 2003 11:10 pm
by McGruff
If your news_news table has a "name" column, you could query the news_news table with:
$mysql = "SELECT ..etc.. WHERE name='$name'";
..to find all submissions by an individual.
Posted: Mon Apr 21, 2003 11:17 pm
by kkurkowski
Don't I have to tell it where it is getting it from like...
Code: Select all
$username = $user
$mysql = "SELECT username FROM news_news WHERE name=$username"
$user is already defined in my script, it will grab the username and replace it with that. So then I add my stuff that I want form there then? Nothin else I should do?
Posted: Mon Apr 21, 2003 11:38 pm
by McGruff
Yes - I simplified the query.
If you want to show a list of links to each of the articles, you might need something like:
Code: Select all
<?php
$mysql = "SELECT aid, article_title FROM news_news WHERE username=$username"
$query = mysql_query($mysql) or die("Cannot query the database.<br>" . mysql_error());
?>
"aid" would be an auto-increment column storing a unique numerical id for each news article.
You could then echo out a list of hyperlinked titles in a while loop:
Code: Select all
<?php
while ($result = mysql_fetch_array($query)) {
echo "<a href="script.php?id=" . $result['aid'] . "">" . $result['article_title'] . "</a>";
}
?>
..obviously you'd replace script.php?id=" . $result['aid'] . " with whatever you use to display a particular article. If you have an "aid" column you can use that to find a particular article.
Late here - off to bed now. Back tomorrow though if you still need some help.
?>
Posted: Mon Apr 21, 2003 11:42 pm
by kkurkowski
Here is the url to my site with the news script on it. I have id's set to each of the articles that are aded, but they don't go by news.php?id=3. It doesn't show them that way.
http://www.bve.32k.org
Posted: Mon Apr 21, 2003 11:55 pm
by kkurkowski
This is what I came up with but it is giving me a error on the while statement.
Code: Select all
<?
require ("news_connect.php");
$result = mysql_query ("SELECT id, headline, user, timestamp FROM news_news ORDER BY timestamp WHERE user=$user");
while ($data = mysql_fetch_array ($result))
{
?>
<table width="425" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td width="20" bgcolor="#BDC1C5"><input type="radio" name="radiobutton" value="<? echo $dataї"id"]; ?>"></td>
<td width="91" bgcolor="#BDC1C5"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $dataї"timestamp"]; ?></font></td>
<td width="306" bgcolor="#BDC1C5"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $dataї"headline"]; ?></font></td>
</tr>
</table><br>
<?
}
?>
Posted: Tue Apr 22, 2003 3:18 am
by McGruff
Delete the semi colon at the end of:
while ($data = mysql_fetch_array ($result));
Lines usually end in semi colons but in this case you're opening up some { }. The other coding style maybe makes it clearer ie:
Code: Select all
<?php
while ($data = mysql_fetch_array ($result)) {
// rest of while loop the code
}
?>
Posted: Tue Apr 22, 2003 9:58 am
by kkurkowski
oppps, The semi colon wasn't suppose to be there, it still errors out on that line when that isn't there too.
Warning: Supplied argument is not a valid MySQL result resource in posts.php on line 42
Line 42 is the while statement.