Jump to content


Photo

echo


  • Please log in to reply
22 replies to this topic

#1 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 07:18 AM

i am trying to add a comment script to my cms on my site, that i just started developing. I am trying to put 2 links into one echo snippet, so that it looks like this "Comments (number of comments) / Post Comment" and the post comment is linked to a post comment script, and the "Comments ()" is linked to a view comments script. I have both the scripts, but I cna't seem to get the links to work. Here is the snippent.

{
	  echo "<tr><td><div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $info_color; border-top: 1px dashed $border_color; text-align: left; <a href=\"news/view_comments.php\">Comments ($comments)</a> / <a href=\"news/post_comment.php\">Post Comment</a> Posted by $r[author] / $r[date]</div></td></tr>\n";
	}

Thanks!

Edited by ShadowDeath01, 04 June 2006 - 07:19 AM.


#2 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 07:32 AM

You left a div tag with a trailing ">" and it was generally a bit messy so i tidied it up a bit.

{
	echo '<tr>
			<td><div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: '.$info_color.'; border-top: 1px dashed '.$border_color.'; text-align: left;"> 
			<a href="news/view_comments.php">Comments ('.$comments.')</a> / 
			<a href="news/post_comment.php">Post Comment</a> Posted by '.$r[author].' / '.$r[date].'
			</div></td></tr>\n';
			
}


#3 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 08:03 AM

OKAY THANKS!!! Now, I need to know something else. How do I get the id of an object out of a SQL table? like, here is example.

id	 title	   author
_
1	  w/e	 XD

I need to get the "1" out of the table, but in a way where it is a variable, such as $id. Thanks. And thanks for fixing my echo code man.

#4 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 09:11 AM

You mean a query?

Well if i include a connetion to start ya off as well, you would use DELETE.

<?php

$config = array(
			 'user' => 'db_username', // Change
			 'pass' => 'db_password', // Change
			 'DB' => 'database_name', // Change
			 'host' => 'localhost' 
			);
	@mysql_connect($config['host'], $config['user'], $config['pass']) or die(mysql_error());
	@mysql_select_db($config['DB']) or die(mysql_error());

(standard mysql connection, just mines a bit snazzier :))

Then use DELETE in a query:

@mysql_query("DELETE FROM `table` WHERE id='$var'") or die(mysql_error());
?>

Obviously $var is your variable :)

Edited by .Matt, 04 June 2006 - 09:47 AM.


#5 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 09:39 AM

I already have the connection, i just need to know how to get the "id" out. did you see my example? i need a way to get the id, so i can make my comments script work for that certain news artice. maybe that helps. like, here are the links i would use would be view_comments.php?id=1 and 1 is the id of the news artice, so the comments posted stay with that certain article. i need something like

$id=mysql_query(SELECT id FROM `news`);
woudl that work to get the id? here is a screenshot of the "id" i am tlaking about.

http://img489.images.../1851/id9fr.jpg there is the screenshot, hope you can help me more

Edited by ShadowDeath01, 04 June 2006 - 09:42 AM.


#6 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 09:48 AM

oh i see sorry. Misunderstood.

Do this:

$Query = @mysql_query("SELECT FROM `news` WHERE id='$var'") or die(mysql_error());

$row = mysql_fetch_array($Query);

echo 'The ID is: '.$row['id'];

I think thats what you mean? $row['id'] is the ID.

#7 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 10:00 AM

what should $var be defined as?

#8 Hayden

Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 717 posts
  • Gender:Male
  • Location:Texas

Posted 04 June 2006 - 10:00 AM

nvm. :)

Edited by SpatialVisionary, 04 June 2006 - 10:01 AM.


#9 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 10:11 AM

$var would be the ID of the post you want...which kinda defeats the object....lol. I must be drunk or something.

Well, maybe not: Do it like this:

select news post
>>> echo news post
>>> take the ID from the original news query using above code

>>> apply the ID to a link to the comment form or similar.

Sorry if it doesnt help much, but you can record the ID when you run a query to show the news post.

Edited by .Matt, 04 June 2006 - 10:12 AM.


#10 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 10:32 AM

so, the $query code above records the ID?

so, the ID can be recorded using the $query variable above?

#11 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 11:11 AM

yeh. Just use the same query that you use to call the data to show the news post, to record the ID.

e.g:

$Query = @mysql_query("SELECT FROM `news` ORDER BY id DESC") or die(mysql_error());

while( $row = mysql_fetch_array($Query) )
{
	  /* show news post here
	  @  e.g $row['title'] / author etc. */

	  echo '<a href="comment.php?cid='.$row['id'].'">Post comment</a>';
}

Where cid is your news post ID.

Edited by .Matt, 04 June 2006 - 12:09 PM.


#12 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 11:33 AM

haha, okay. i get that part, but i am still stuck on $var what does it need to be defined as?

#13 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 12:09 PM

$var is the ID of the news post you want. I achually forgot to change that sorry, look at the above post again.

#14 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 12:31 PM

okay dude, thanks.

#15 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 12:35 PM

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `qlitenews` ORDER BY id DESC' at line 1

I got that error, and I fixed everything I could see wrong. here is the code.

<?php 

  include("admin/config.php");
  
  $db = mysql_connect($dbhost,$dbuser,$dbpass); 
  mysql_select_db($dbname) or die("Cannot connect to database");
  $query = "SELECT * FROM qlitenews ORDER BY id $news_format LIMIT $news_limit"; 
  $result = mysql_query($query);
  $comments= @mysql_num_rows(mysql_query("SELECT * FROM `reply` ORDER BY id"));
  $Query = mysql_query("SELECT FROM `qlitenews` ORDER BY id DESC") or die(mysql_error());

while( $row = mysql_fetch_array($Query) )
{

  echo "<table>";
  while ($r = mysql_fetch_array($result)) {
	echo "
	  <tr><td><span style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $head_color; font-weight: bold;\">$r[title]</span></td></tr>
	  <tr><td><span style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $body_color\">$r[news]</span></td></tr>\n";
	if ($news_info == 1) {
	  echo "<tr><td><div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $info_color; border-top: 1px dashed $border_color; text-align: left;\"> <a href=\"news/view_comments.php?id=".$row['id']."\">Comments ($comments)</a> / <a href=\"news/post_comment.php?id=".$row['id']."\">Post Comment</a></div>  <div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $info_color; text-align: right;\">Posted by $r[author] / $r[date]</div></td></tr>\n";
	  }
	}
  }
echo "</table>\n";

?>

I know it is a little messy. lol but o well.

http://gfxtuts4you.co.nr is the site, if you wanna see the error

Edited by ShadowDeath01, 04 June 2006 - 12:39 PM.


#16 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 01:01 PM

I tidied it up a bit and fixed it *hope*.
Your queries are confusing so just shout back if i created an error lol.

<?php

  include("admin/config.php");
  
  $db = mysql_connect($dbhost,$dbuser,$dbpass);
  mysql_select_db($dbname) or die('Cannot connect to database'.mysql_eror());
  
  $CQuery = @mysql_query("SELECT * FROM `reply`") or die(mysql_error());
  
  $comments= mysql_num_rows($CQuery); 
  
  $Query = @mysql_query("SELECT * FROM `qlitenews` ORDER BY id $news_format LIMIT $news_limit") or die(mysql_error());


  echo "<table>";
  while ( $r = mysql_fetch_array($Query) ) 
  {
	echo "
	  <tr><td><span style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $head_color; font-weight: bold;\">$r[title]</span></td></tr>
	  <tr><td><span style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $body_color\">$r[news]</span></td></tr>\n";
	if ($news_info == 1) 
	{
	  echo "<tr><td>
	<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $info_color; border-top: 1px dashed $border_color; text-align: left;\"> 
	<a href=\"news/view_comments.php?id=".$r['id']."\">Comments ($comments)</a> / 
	<a href=\"news/post_comment.php?id=".$r['id']."\">Post Comment</a>
	</div>  
	<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: $info_color; text-align: right;\">
	Posted by $r[author] / $r[date]
	</div>
	</td></tr>\n";
	  
	  }
	
	}

echo "</table>\n";

?>

Try and use single quites and '.$row['bla'].' instead of escaping with \" btw ;)

I havent done that in the modified code though, its up to you if you want it that way ;)

btw: On your comments query, you are selecting all of the comments you know? not just comments relating to that article. You need to put it within the while loop and use a WHERE to make it select comments only for the showing article.

Edited by .Matt, 04 June 2006 - 01:05 PM.


#17 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 01:06 PM

yes i know, thank you for fixing it man, it works now. thank you. what would the query be to select comments just for that article? also, what was wrong?

Edited by ShadowDeath01, 04 June 2006 - 01:07 PM.


#18 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 04 June 2006 - 01:30 PM

You forgot a * after SELECT and also there were 2 queries named the same which kinda screwed it up.

For the coments, you need to put this query within the while {} loop. (after the {

$nc = @mysql_query("SELECT FROM `replys` WHERE field='$row[id]'") or die(mysql_error());

$comments = mysql_num_rows($nc);


I have put "field" in bold as field is the field that you are using to link the comments with the news article. Its gotta be changed accordingly.

Edited by .Matt, 04 June 2006 - 01:30 PM.


#19 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 02:00 PM

Unknown column 'field' in 'where clause'

that is what i got after i removed the CQuery, and $comments that was in the code before. how do i fix this?

Edited by ShadowDeath01, 04 June 2006 - 02:04 PM.


#20 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 04 June 2006 - 02:15 PM

okay, i figured out the field thing, but i odn't have a fienld in the dql that matches. id won't do it. becuaese it chages with all the new comments that are added. got any ideas?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users