Adding edit tables
Moderator: General Moderators
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
Adding edit tables
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!!
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.
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.
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
Don't I have to tell it where it is getting it from like...
$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?
Code: Select all
$username = $user
$mysql = "SELECT username FROM news_news WHERE name=$username"Yes - I simplified the query.
If you want to show a list of links to each of the articles, you might need something like:
"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:
..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.
?>
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());
?>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>";
}
?>Late here - off to bed now. Back tomorrow though if you still need some help.
?>
Last edited by McGruff on Thu Aug 11, 2005 11:18 am, edited 1 time in total.
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
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
http://www.bve.32k.org
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
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>
<?
}
?>
Last edited by kkurkowski on Tue Apr 22, 2003 10:15 am, edited 1 time in total.
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:
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
}
?>
Last edited by McGruff on Thu Aug 11, 2005 11:18 am, edited 1 time in total.
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan