It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Display only relevant rows from mysql via php

Moderator: Malcolm

Display only relevant rows from mysql via php

Postby thedrumguy on Sun Apr 24, 2011 2:17 am

Hello, I'm trying to create my own forum with php, and I've got mysql set up in this way (created with Dreamweaver):
Original Post Table:
poster: name of user that posted the topic
topic
post

Replies to posts:
replier: who posted it
reply_topic: what the person is replying to (used to show only relevant rows)
reply_post: content

I want to use reply_topic to show rows of data from the reply table that are relevant to the original post. What would I need to add in to do this? Currently, with the code (below), all of the data, regardless of where it was posted to, is displayed on every topic. If I wasn't clear enough, please let me know!

Code: Select all
Head:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_main_topic = "-1";
if (isset($_GET['post'])) {
  $colname_main_topic = $_GET['post'];
}
mysql_select_db($database_mysql1, $mysql1);
$query_main_topic = sprintf("SELECT * FROM aka_forum_main_post WHERE post = %s", GetSQLValueString($colname_main_topic, "text"));
$main_topic = mysql_query($query_main_topic, $mysql1) or die(mysql_error());
$row_main_topic = mysql_fetch_assoc($main_topic);
$totalRows_main_topic = mysql_num_rows($main_topic);

mysql_select_db($database_mysql1, $mysql1);
$query_replies = "SELECT * FROM aka_forum_post_reply";
$replies = mysql_query($query_replies, $mysql1) or die(mysql_error());
$row_replies = mysql_fetch_assoc($replies);
$totalRows_replies = mysql_num_rows($replies);
?>

Code: Select all
Body:
<!-- start original post -->
<table width="500" border="1">
  <tr>
    <td width="100"><?php echo $row_main_topic['poster']; ?></td>
    <td width="400"><?php echo $row_main_topic['post']; ?></td>
  </tr>
</table>
<!-- start all replies -->
<table border="1" width="500">
  <tr>
    <td width="100">replier</td>
    <td width="400">reply_post</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_replies['replier']; ?></td>
      <td><?php echo $row_replies['reply_post']; ?></td>
    </tr>
    <?php } while ($row_replies = mysql_fetch_assoc($replies)); ?>
</table>
thedrumguy
 
Posts: 5
Joined: Tue Mar 23, 2010 2:44 pm

Re: Display only relevant rows from mysql via php

Postby rajmv on Sun Jul 17, 2011 5:32 pm

The "orginal post table" needs an (auto_increment) id per row.

The "replies to post" needs that same id and another (auto_increment) id per row.

And i'd look into http://adodb.sourceforge.net/ if i were you

And a search for "link sql tables" on google might help you as well.

Good luck :)
rajmv
100+ Club
 
Posts: 103
Joined: Thu Jul 14, 2011 7:22 am

Re: Display only relevant rows from mysql via php

Postby wajidwarraich on Wed Oct 05, 2011 12:27 pm

:D
rajmv wrote:The "orginal post table" needs an (auto_increment) id per row.

The "replies to post" needs that same id and another (auto_increment) id per row.

And i'd look into http://adodb.sourceforge.net/ if i were you

And a search for "link sql tables" on google might help you as well.

Good luck :)

good dear its a best effort
wajidwarraich
 
Posts: 1
Joined: Wed Oct 05, 2011 12:19 pm


Who is online

Users browsing this forum: No registered users and 1 guest