NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Another problem. Sorry

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-22-2005, 11:06 AM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Another problem. Sorry


Sorry, I know I've asked a lot of questions but this SHOULD be the last.. for now. lol, just kidding.

Right, When a user submits a new thread on my forum, the thread is inserted into my "threads" table in the database and the post is submitted into the "posts" table at the same time. The thread is represented in the "threads" column of the "posts" table as a number (the id of the thread).

But the post is submitted at the same time as the thread so how will I be able to assign the post to the correct thread?

I hope that makes sense. Sorry if i wasn't very clear
Encenta.com is offline  
Old 10-22-2005, 11:15 AM   #2 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Hello,

It is kinda confusing but I kinda get it. You can have a table in Posts called tid which carries thread id.

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 11:30 AM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thanks for the reply. I have a threadID column in the posts table but I'm unsure how to insert the new thread ID into it the same time it is being created. I'll try and illustrate the tables:

Posts:
ID, category, threadid, author, content, time, date

Threads:
ID, title, author, starttime, startdate

Then as you can imagine, as the user submits a new thread, I want the post inserted into the "posts" table as well as the thread into the "threads" table
Encenta.com is offline  
Old 10-22-2005, 11:33 AM   #4 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Hello,

First create the thread than use mysql_insert_id and set threadid and insert post.

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 11:50 AM THREAD STARTER               #5 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thanks iNod. That's definately the correct method but I think I'm going wrong somewhere. it's inserting into the database the actual text "mysql_insert_id". Here's my code:

PHP Code:
$lastid mysql_insert_id();

$query2 "INSERT INTO posts VALUES ('id', '$category', $lastid, '$author', '$msg', '$starttime', '$startdate')";
$results2 mysql_query($query2); 
????: NamePros.com http://www.namepros.com/programming/133998-another-problem-sorry.html
EDIT: Also, I get a very frustrating repetition:

http://www.darkfx.co.uk/darkfx/threads.php?category=1
Last edited by Encenta.com; 10-22-2005 at 12:12 PM.
Encenta.com is offline  
Old 10-22-2005, 12:20 PM   #6 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Ouch.. I suggest deleting that script from ftp right away.. Thats a major BW hog.

Now.. Lets fix it up.
First thing put ' (quotes) around $lastid

The rest seems to be correct can you post rest of php.

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 12:54 PM THREAD STARTER               #7 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




lol. removed script for now

PHP Code:
if ($_POST['submitthread']) {
$msg=$_POST['msg'];
????: NamePros.com http://www.namepros.com/showthread.php?t=133998
$title=$_POST['title'];
$starttime=date("H:i"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=133998
$startdate=date("d/m/y");





$query "INSERT INTO forum_threads VALUES ('id', '$title', '$author', '$category', '$starttime', '$startdate')";
$results mysql_query($query);


$lastid mysql_insert_id();

$query2 "INSERT INTO forum VALUES ('id', '$category', '$lastid', '$author', '$msg', '$starttime', '$startdate')";
$results2 mysql_query($query2);

if (!
$result) {
include(
"head.php");
echo(
"<h1>Success</h1> <p>Post added successfully. <a href='thread.php?category=$category&thread=$lastid'>Return to forum</a></p>
"
);
include(
"foot.php");
exit;
}} 
Encenta.com is offline  
Old 10-22-2005, 01:16 PM   #8 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
PHP Code:
if($_POST['submitthread']) {
$msg=$_POST['msg'];
$title=$_POST['title'];
$starttime=date("H:i");
$startdate=date("d/m/y");





$query "INSERT INTO forum_threads VALUES ('$title', '$author', '$category', '$starttime', '$startdate')";
$results mysql_query($query);


$lastid mysql_insert_id();

$query2 "INSERT INTO forum VALUES ('$category', '$lastid', '$author', '$msg', '$starttime', '$startdate')";
$results2 mysql_query($query2);

if (!
$result) {
include(
"head.php");
echo(
"<h1>Success</h1> <p>Post added successfully. <a href='thread.php?category=$category&thread=$lastid'>Return to forum</a></p>
????: NamePros.com http://www.namepros.com/showthread.php?t=133998
????: NamePros.com http://www.namepros.com/showthread.php?t=133998
"
);
include(
"foot.php");
exit;
}

Is there any code about that like while or foreach?

I am wondering why it is looping.

iNod
__________________
I feel old.
iNod is offline  
Old 10-22-2005, 01:27 PM THREAD STARTER               #9 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Well, the page which displays the threads is:

PHP Code:
<?
include("config.php");
$category $_GET['category'];
$newthread $_GET['newthread'];
session_start();
$author $_SESSION['username'];

// DISPLAY THREADS
if (isset($_GET['category'])) {


$result mysql_query("SELECT * FROM categories WHERE id='$category'"
or die(
"SELECT Error1: " .mysql_error());
$num=mysql_numrows($result);
while (
$row mysql_fetch_array($result)) 

$title $row['title'];
}
$pagetitle "$title threads";
include(
"head.php");

echo 
"<h1>$title forum</h1>
<table width='100%' border='0'>
<tr><td align='left'><p><a href='forum.php'>&lt; Back to categories</a></p></td>
<td align='right'><p><a href='forumhandle.php?newthread=true&category=
$category'>Start new thread</a></p></td></tr></table>";
echo 
"<table width='100%' border='0' cellspacing=0 cellpadding=2>
<tr class='threadhead'>
    <td width='40%'>Thread</td>
    <td width='25%'>Thread Started</td>
    <td width='25%'>Last Post</td>
    <td width='10%'>Posts</td>
</tr>"
;
// END OF HEADINGS





$result mysql_query("SELECT * FROM forum_threads WHERE category='$category' ORDER BY id DESC"
????: NamePros.com http://www.namepros.com/showthread.php?t=133998
or die(
"SELECT Error1: " .mysql_error());
$num=mysql_numrows($result);


$i=0;
while (
$i $num) {
if (
$i 2) {
$bgcolor "threadtable";
            }
else {
$bgcolor "threadtable2";
     }



$id=mysql_result($result,$i,"id");
$title=mysql_result($result,$i,"title");
$author=mysql_result($result,$i,"author");
$category=mysql_result($result,$i,"category");
$startdate=mysql_result($result,$i,"startdate");
????: NamePros.com http://www.namepros.com/showthread.php?t=133998
$starttime=mysql_result($result,$i,"starttime");


$query mysql_query"SELECT * FROM forum WHERE threadid='$id' AND category='$category'" ) or die("SELECT Error2: " .mysql_error());
$numero=mysql_numrows($query);
$query mysql_query"SELECT id FROM users WHERE username='$author'" ) or die("SELECT Error3: " .mysql_error());
$authorid=mysql_result($query,0,"id");


$query mysql_query"SELECT * FROM forum WHERE threadid='$id' AND category='$category' ORDER BY 'datetime' ASC LIMIT 1" ) or die("SELECT Error4: " .mysql_error());
$num1=mysql_numrows($query);
$i=0;
while (
$i $num1) {
$author=mysql_result($query,$i,"author");
$time=mysql_result($query,$i,"time");
$date=mysql_result($query,$i,"date");
$today date("d/m/y");

if (
$date == $today) {$date "Today"; }
{
$date "Today";}
$i++;
}







echo 
"
  <tr class='
$bgcolor'>
    <td valign='top'><a href='showthread.php?category=
$category&thread=$id'>$title</a></td>
    <td valign='top'>
$startdate at $starttime <br />by <a href='viewprofile?profile_id=$authorid'>$author</a></td>
    <td valign='top'>
$date at $time</td>
    <td valign='top'>
$numero</td>
  </tr>"
;
     
$i++;
}
echo 
"</table>";
include(
"foot.php");
}
// END DISPLAY THREADS

?>
There are a few loops. But I think it's because of the database content which was the reason it was repeating
Encenta.com is offline  
Old 10-23-2005, 01:51 PM THREAD STARTER               #10 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




I got the ThreadID thing orking. But the problem now is that when displaying the threads, it isn't looping. It only displays the last row in the database
Encenta.com is offline  
Old 10-23-2005, 02:16 PM   #11 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Hello,

Get read of that while $i stuff. Use this format

PHP Code:
$query mysql_query("SELECT * FROM bob");
????: NamePros.com http://www.namepros.com/showthread.php?t=133998

while(
$row mysql_fetch_array($query)) {
print 
"Bob eats $row['candy']";

Above says.
Select all from bob. (Table I made was candy)
While $row is equal to mysql_fetch_array do.
print "Bob eats candy or what not";
}

iNod
__________________
I feel old.
iNod is offline  
Old 10-23-2005, 02:40 PM THREAD STARTER               #12 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thank you so much once again! NP$ donated!!
Encenta.com is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Prozilla Image Hosting Script Maverick Website Development 3 02-01-2006 03:32 PM
Very wierd Windows problem Ravi_s Web Design Discussion 0 08-12-2005 10:29 PM
MySQL or PHP problem Wildchild22 Website Development 10 07-14-2005 05:24 AM
vBulletin Problem!!!!!!!!!!!! domaino Programming 11 06-23-2005 06:29 AM

 
All times are GMT -7. The time now is 02:02 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger