Multiple rows in mysql

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post June 22nd, 2006, 9:17 am

thank you so much
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 22nd, 2006, 9:17 am

  • knexor2
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 27, 2006
  • Posts: 445
  • Loc: US
  • Status: Offline

Post June 22nd, 2006, 2:03 pm

Eh...just thought I'd throw out this little function for you...

nl2br()
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post June 22nd, 2006, 2:16 pm

and that does?
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • knexor2
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 27, 2006
  • Posts: 445
  • Loc: US
  • Status: Offline

Post June 22nd, 2006, 2:19 pm

Click the link :P

It places <br />'s before each newline in the given string.

nl2br("Hello\nworld") = Hello<br />\nworld
"People can school you, but you must educate yourself." ~ John Taylor Gatto
Tech Knack Blog
The purpose of these forums is not to get an answer, but to learn an answer.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post July 1st, 2006, 5:52 am

ok thank you for the comment thing and things but now i was wondering on how i can delete them like a piticular comment. I have put in like a id system in the database.

Image

that is what it looks like now. can anybody help me?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Joined: Nov 11, 2004
  • Posts: 583
  • Loc: Nimes (France)
  • Status: Offline

Post July 2nd, 2006, 1:34 am

HI, I would be happy to help you but I don't really understand the question in fact :-)
What does "piticular" mean, I found nothing on english-french traductors :scratchhead: .

Do you mean you've got the comment ID and want to delete him?

in a usual way you do :
PHP Code: [ Select ]
//...
 
$q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$given_id." LIMIT 1";
 
mysql_query($q) or die (mysql_error()."<br />".$q);
 
 
  1. //...
  2.  
  3. $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$given_id." LIMIT 1";
  4.  
  5. mysql_query($q) or die (mysql_error()."<br />".$q);
  6.  
  7.  

Or maybe you want a more complex delete based on a table join?
or what about "like a ID system"?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post July 2nd, 2006, 3:57 pm

ok what i want to do is put a button under reply to post that says delete and have it delete that comment. and i have each of the comments a automatic id number!
  • gisele
  • Expert
  • Expert
  • User avatar
  • Joined: Nov 11, 2004
  • Posts: 583
  • Loc: Nimes (France)
  • Status: Offline

Post July 3rd, 2006, 1:06 am

forget this one, I quoted myself instead of edit :-)
  • gisele
  • Expert
  • Expert
  • User avatar
  • Joined: Nov 11, 2004
  • Posts: 583
  • Loc: Nimes (France)
  • Status: Offline

Post July 3rd, 2006, 1:08 am

Ok , so that's very simple,

While querying the comments in order to display them, think about getting the comment ID,
dipslay a self link (to the same script but with a parameter del=id_comment to remove) for example :


just bellow the reply link :
PHP Code: [ Select ]
//...
 
print "<a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Remove</a>";
 
 
  1. //...
  2.  
  3. print "<a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Remove</a>";
  4.  
  5.  


At the biggining of this same script you just test $_GET["del"], that'll mean that the link was clicked before and you 've got to do a delete stuff (assuming that TBL_COMMENT has been defined):
PHP Code: [ Select ]
//...
 
if(isset($_GET["del"]))
 
{
 
   $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
 
   mysql_query($q) or die (mysql_error()."<br />".$q);
 
}
 
 
  1. //...
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. {
  6.  
  7.    $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
  8.  
  9.    mysql_query($q) or die (mysql_error()."<br />".$q);
  10.  
  11. }
  12.  
  13.  

And then, once this comment isn't anymore in the DB, go on with the comment displaying stuff like you've yet made it, thinking about adding the remove links abobe for each comment ...

In fact, the comment displaying script will call itself saying do a delete stuff before showing the comment
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post July 4th, 2006, 4:40 pm

gisele wrote:
PHP Code: [ Select ]
//...
if(isset($_GET["del"]))
{
   $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
   mysql_query($q) or die (mysql_error()."<br />".$q);
}
 
  1. //...
  2. if(isset($_GET["del"]))
  3. {
  4.    $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
  5.    mysql_query($q) or die (mysql_error()."<br />".$q);
  6. }
  7.  


so this right here do i put it in my database.php or where?

also for some reason this will not work and i dont know why. its deleting a user from the database.

PHP Code: [ Select ]
   function procDeleteUser(){
 
      global $session, $database, $form;
 
      /* Username error checking */
 
      $subuser = $this->checkUsername("deluser");
 
     
 
      /* Errors exist, have user correct them */
 
      if($form->num_errors > 0){
 
         $_SESSION['value_array'] = $_POST;
 
         $_SESSION['error_array'] = $form->getErrorArray();
 
         header("Location: ".$session->referrer);
 
      }
 
      /* Delete user from database */
 
      else{  
 
      if($database->AdminDeleteComments($deluser)){
 
        if($database->AdminDeleteProfile($deluser)){
 
       if($database->AdminDeleteMoreComments($deluser)){
 
       if($database->AdminDeleteActive($deluser)){
 
         }
 
         }
 
       }
 
       }
 
       header("Location:".$session->referrer);
 
      }
 
   }
  1.    function procDeleteUser(){
  2.  
  3.       global $session, $database, $form;
  4.  
  5.       /* Username error checking */
  6.  
  7.       $subuser = $this->checkUsername("deluser");
  8.  
  9.      
  10.  
  11.       /* Errors exist, have user correct them */
  12.  
  13.       if($form->num_errors > 0){
  14.  
  15.          $_SESSION['value_array'] = $_POST;
  16.  
  17.          $_SESSION['error_array'] = $form->getErrorArray();
  18.  
  19.          header("Location: ".$session->referrer);
  20.  
  21.       }
  22.  
  23.       /* Delete user from database */
  24.  
  25.       else{  
  26.  
  27.       if($database->AdminDeleteComments($deluser)){
  28.  
  29.         if($database->AdminDeleteProfile($deluser)){
  30.  
  31.        if($database->AdminDeleteMoreComments($deluser)){
  32.  
  33.        if($database->AdminDeleteActive($deluser)){
  34.  
  35.          }
  36.  
  37.          }
  38.  
  39.        }
  40.  
  41.        }
  42.  
  43.        header("Location:".$session->referrer);
  44.  
  45.       }
  46.  
  47.    }


and this is the databse
PHP Code: [ Select ]
function AdminDeleteComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where postusername = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
               function AdminDeleteMoreComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where username = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }  
 
         
 
    function AdminDeleteProfile($deluser){
 
        $q = "DELETE from ".TBL_USERS." where username = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
          function AdminDeleteActive($deluser){
 
        $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }
  1. function AdminDeleteComments($deluser){
  2.  
  3.         $q = "DELETE from ".TBL_COMMENTS." where postusername = '$subuser'";
  4.  
  5.       return mysql_query($q, $this->connection);
  6.  
  7.            }
  8.  
  9.                function AdminDeleteMoreComments($deluser){
  10.  
  11.         $q = "DELETE from ".TBL_COMMENTS." where username = '$subuser'";
  12.  
  13.       return mysql_query($q, $this->connection);
  14.  
  15.            }  
  16.  
  17.          
  18.  
  19.     function AdminDeleteProfile($deluser){
  20.  
  21.         $q = "DELETE from ".TBL_USERS." where username = '$subuser'";
  22.  
  23.       return mysql_query($q, $this->connection);
  24.  
  25.            }
  26.  
  27.           function AdminDeleteActive($deluser){
  28.  
  29.         $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$subuser'";
  30.  
  31.       return mysql_query($q, $this->connection);
  32.  
  33.            }


what is wrong with that? it is not working at all? why is that?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Joined: Nov 11, 2004
  • Posts: 583
  • Loc: Nimes (France)
  • Status: Offline

Post July 5th, 2006, 3:15 am

Hi,
the local variable name is changed
between
AdminDeleteComments($deluser)
and
where postusername = '$subuser'";

that should be :
where postusername = '$deluser'";


And my script yeah you can make it like a member function of database database::DeleteComment() (like user deleting ones).
And call it just before querying and displaying the comment
if(isset($_GET["del"]))
$database->DeleteComment();
____________________
My web site[/url] oh sh..!
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post July 5th, 2006, 2:42 pm

hi i put the thing in for the comments and it did not work

PHP Code: [ Select ]
<a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Delete Comment</a


and
PHP Code: [ Select ]
 <?php //...
 
if(isset($_GET["del"]))
 
$database->DeleteComment();
 
 ?>
  1.  <?php //...
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. $database->DeleteComment();
  6.  
  7.  ?>


and for the database
PHP Code: [ Select ]
function DeleteProfileComment(){
 
      $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";  
 
       return mysql_query($q, $this->connection);  
 
      }
  1. function DeleteProfileComment(){
  2.  
  3.       $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";  
  4.  
  5.        return mysql_query($q, $this->connection);  
  6.  
  7.       }




also that did not work for the admin thing

PHP Code: [ Select ]
else{  
 
      if($database->AdminDeleteComments($deluser)){
 
        if($database->AdminDeleteProfile($deluser)){
 
       if($database->AdminDeleteMoreComments($deluser)){
 
       if($database->AdminDeleteActive($deluser)){
 
         }
 
         }
 
       }
 
       }
 
       header("Location:".$session->referrer);
 
      }
  1. else{  
  2.  
  3.       if($database->AdminDeleteComments($deluser)){
  4.  
  5.         if($database->AdminDeleteProfile($deluser)){
  6.  
  7.        if($database->AdminDeleteMoreComments($deluser)){
  8.  
  9.        if($database->AdminDeleteActive($deluser)){
  10.  
  11.          }
  12.  
  13.          }
  14.  
  15.        }
  16.  
  17.        }
  18.  
  19.        header("Location:".$session->referrer);
  20.  
  21.       }


PHP Code: [ Select ]
  function AdminDeleteComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where postusername = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
               function AdminDeleteMoreComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where username = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }  
 
         
 
    function AdminDeleteProfile($deluser){
 
        $q = "DELETE from ".TBL_USERS." where username = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
          function AdminDeleteActive($deluser){
 
        $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }
  1.   function AdminDeleteComments($deluser){
  2.  
  3.         $q = "DELETE from ".TBL_COMMENTS." where postusername = '$deluser'";
  4.  
  5.       return mysql_query($q, $this->connection);
  6.  
  7.            }
  8.  
  9.                function AdminDeleteMoreComments($deluser){
  10.  
  11.         $q = "DELETE from ".TBL_COMMENTS." where username = '$deluser'";
  12.  
  13.       return mysql_query($q, $this->connection);
  14.  
  15.            }  
  16.  
  17.          
  18.  
  19.     function AdminDeleteProfile($deluser){
  20.  
  21.         $q = "DELETE from ".TBL_USERS." where username = '$deluser'";
  22.  
  23.       return mysql_query($q, $this->connection);
  24.  
  25.            }
  26.  
  27.           function AdminDeleteActive($deluser){
  28.  
  29.         $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$deluser'";
  30.  
  31.       return mysql_query($q, $this->connection);
  32.  
  33.            }
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post July 5th, 2006, 9:58 pm

well i got the admin delete user working but the delete comment is still not working from the code that you had gaven me!
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • gisele
  • Expert
  • Expert
  • User avatar
  • Joined: Nov 11, 2004
  • Posts: 583
  • Loc: Nimes (France)
  • Status: Offline

Post July 6th, 2006, 12:17 am

Hi,

could you show me the concerned parts (delete function + function call + link) of the script please, it'll be easier to see what detail is wrong and to make it work
____________________
My web site[/url] oh sh..!
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post July 6th, 2006, 8:16 am

Database
PHP Code: [ Select ]
     
 
   function DeleteProfileComment($del){
 
      $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET[$del]." LIMIT 1";  
 
       return mysql_query($q, $this->connection);  
 
      }
  1.      
  2.  
  3.    function DeleteProfileComment($del){
  4.  
  5.       $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET[$del]." LIMIT 1";  
  6.  
  7.        return mysql_query($q, $this->connection);  
  8.  
  9.       }


my comments
PHP Code: [ Select ]
<?php //...
 
if(isset($_GET["del"]))
 
$database->DeleteComment("del");
 
 ?> <?php
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))
 
          {
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
 
 
 
 
 
";
 
 
 
           }
 
           ?>
  1. <?php //...
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. $database->DeleteComment("del");
  6.  
  7.  ?> <?php
  8.  
  9.           while($req_user_postusername = mysql_fetch_array($rs_pointer))
  10.  
  11.           {
  12.  
  13. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
  14.  
  15.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
  16.  
  17.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
  18.  
  19.  
  20.  
  21.  
  22.  
  23. ";
  24.  
  25.  
  26.  
  27.            }
  28.  
  29.            ?>
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 6th, 2006, 8:16 am

Post Information

  • Total Posts in this topic: 97 posts
  • Users browsing this forum: No registered users and 96 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.