Re: foreign key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Okay. I just validated it is not in the left join query, but in my php. I
was able to build the correct relations.

Does anyone see any think in the php code below that may cause duplicate
table rows?

Thank you all.

<?php
//store.php
include_once 'includes/connect.php';
include_once 'includes/header.php';
print("<pre>".print_r($_GET,true)."</pre>");
$sql = "SELECT store_id, store_subject, store_comments, store_date,
store_tptest, store_by
 FROM stores
 WHERE store_subject = '" . mysql_real_escape_string($_GET['id'])."'";
$result = mysql_query($sql);
if(!$result)
{
 echo 'The latest post could not be displayed, please try again later.';
 //echo mysql_error(); //debugging purposes, uncomment when needed

}
else
{
 if(mysql_num_rows($result) == 0)
 {
  echo 'This store visit doesn&prime;t exist.';
 }
 else
 {
  while($row = mysql_fetch_assoc($result))
  {
   //display post data
   echo '<table class="table1" border="1">
     <tr>
      <th colspan="2">' . $row['store_subject'] . '</th>
     </tr>';

   //fetch the posts from the database
   $posts_sql = "SELECT
      stores.store_subject,
      stores.store_comments,
      stores.store_date,
      stores.store_tptest,
      stores.store_by,
      users.user_id,
      users.user_name,
      users.first_name,
      users.last_name
     FROM
      stores
     LEFT JOIN
      users
     ON
      stores.store_by = users.user_id
     WHERE
      stores.store_subject = '" . mysql_real_escape_string($_GET['id'])."'
     ORDER BY
      stores.store_date DESC ";

      //echo $posts_sql;

   $posts_result = mysql_query($posts_sql);

   if(!$posts_result)
   {
    echo '<tr><td>The posts could not be displayed, please try again
later.</tr></td></table>';
    //echo mysql_error(); //debugging purposes, uncomment when needed
   }
   else
   {

    while($posts_row = mysql_fetch_assoc($posts_result))
    {
     echo '<tr class="topic-post">
       <td class="user-post">' . $posts_row['first_name'] . ' ' .
$posts_row['last_name'] . '<br/>' . date('m-d-Y h:iA',
strtotime($posts_row['store_date'])) . '</td>
       <td class="post-content">' . $posts_row['store_tptest'] . '<br/>' .
htmlentities(stripslashes($posts_row['store_comments'])) . '</td>
        </tr>';
    }
   }

   if(!$_SESSION['signed_in'])
   {
    echo '<tr><td colspan=2>You must be <a href="signin.php">signed in</a>
to reply. You can also <a href="signup.php">sign up</a> for an account.';
   }
   else
   {
    //show reply box
    echo '<tr><td colspan="2"><h2>Reply:</h2><br />
     <form method="post" action="reply.php?id=' . $row['store_id'] . '">
      <textarea name="reply-content"></textarea><br /><br />
      <input type="submit" value="Submit reply" />
     </form></td></tr>';
   }

   //finish the table
   echo '</table>';
  }
 }
}
include_once 'includes/footer.php';
?>

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux