SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    querying a table

    Hi Guys,

    i have 2 main tables "membership" and "member_comments" i have made a page which trys to pull out the data according to who is logged in my script is like this:

    PHP Code:
    <?php
         
    // For register_global on PHP settings//////////////////////////////////////////////
         
    $member $_COOKIE['member'];

         
    session_start(); // you must put this to read session variables/////////////////////

         
    if (empty($member) || !isset($member)) // fail to read the browser cookie///////////
         
    {
         
    // Try to read session
         
    if (empty($_SESSION['member']) || !isset($_SESSION['member']))
         {
               
    header("Location: login.php"); // redirect user to login//////////////////////
               
    exit;
         } else {
              
    $member $_SESSION['member'];
      }
    }
         
    //Includes... //////////////////////////////////////////////////////////////////////
         
    include("includes/db_connection.php");
         include(
    "includes/constants.php");
         include(
    "includes/header.php");
         include(
    "includes/loginnav.php");
         
         
    $query "SELECT id,username FROM membership WHERE username='$member' LIMIT 1";
         
    $result_query mysql_query($query) or die(mysql_error());
         
         while(
    $result_array mysql_fetch_array($result_query)) {
    ?>
    <p align="left">Welcome, <b><font color="#3399ff"><? echo $_COOKIE['member'?></font></b>! (<a href="logout.php">Logout</a>) - [ <a href="change_password.php">Change Password Or E-mail Address</a> ]-[ <a href="edit_profile.php">Edit Profile</a> ]-[ <a href="upload_photo.php">Upload Photo</a> ]-[ <?php echo "<a href='profile.php?id=$result_array[id]'>View My Profile</a>"?> ]-[ <a href="edit_blog.php">Edit Blog</a> ]</p>
    </p>
    <?php
    }
    ?>
    <p>Edit The Comments On Your Profile Blog Below:</p>
    <?php 
         
    // Make a query to retrieve the comments.../////////////////////////////////////////
         
    $query2 "SELECT * FROM member_comments WHERE uid='$member' LIMIT 1";
         
    $result2 mysql_query($query2) or die(mysql_error());
         
         while (
    $row mysql_fetch_array($result2)){
         
                  
    $mid $row['mid'];
                  
    $comments $row['comments'];
                 
                  
                  echo 
    $comments;
                  echo 
    "<br />";

         }
    ?>
    what was trying to do is display the "posted comments" for the logged in user so they could then "edit or delete" them, but im not having much luck with the quer i can SELECT * FROM member_comments fine, but i only want the comments displayed for that particular logged in user not EVERY comment ever posted lol

    heres the .sql for member_comments if it's needed

    PHP Code:
    CREATE TABLE `member_comments` (
      `
    idint(5NOT NULL auto_increment,
      `
    midvarchar(5NOT NULL default '',
      `
    uidvarchar(5NOT NULL default '',
      `
    commentstext NOT NULL,
      `
    posteddatetime NOT NULL default '0000-00-00 00:00:00',
      
    PRIMARY KEY  (`id`)
    ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=33 
    Thanks for nay help

    Graham

  2. #2
    SitePoint Enthusiast Hexlo's Avatar
    Join Date
    Feb 2007
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    I am assuming in this post that uid is the id of the user who posted it and there name is stored in a session. All you would need to do is below:
    PHP Code:
    <?
    $userid 
    mysql_real_escape_string($_SESSION['uid']);
    $query mysql_query("SELECT * FROM `member_comments` WHERE `uid` = '$userid'");
    // then you would need to manipulate/show:
    while($row mysql_fetch_array($query)) {
    // echo data here
    }
    ?>
    Hope that helps with what your trying to achieve.
    Edit:

    IF your having more problems feel free to PM me.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •