Adding edit tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Adding edit tables

Post 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!!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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??
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

By the way, I am using MySQL to do this too.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

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

Post 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
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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))
&#123;
?>
<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&#1111;"id"]; ?>"></td>
    <td width="91" bgcolor="#BDC1C5"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $data&#1111;"timestamp"]; ?></font></td>
    <td width="306" bgcolor="#BDC1C5"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $data&#1111;"headline"]; ?></font></td>
  </tr>
</table><br>
<?
&#125;
?>
Last edited by kkurkowski on Tue Apr 22, 2003 10:15 am, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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

}
?>
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

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