Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using variables of the current page in an include ???
Old 07-13-2010, 05:05 PM Using variables of the current page in an include ???
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Hey guys, tough question here...

I have a config.php file, that lets you set up the site. However, the config needs a variable to set something each time. Hard to explain, let me show you.

PHP Code:
<form action='edit.php?r=".$row['replyID']."' method='post'>
<
input class='imgsubmit' type='image' src='images/edit.png' alt='Edit'>
</
form
It's a form. When you submit it, I want it to go to the current replyID, taken from a database. Here's the code that sets the $row field.

PHP Code:
$result mysql_query("SELECT * FROM $DBpostsTable WHERE threadID = '$threadID' ORDER BY replyID");
  while(
$row mysql_fetch_array($result))
    {
       ...
    } 
Ok... A bit tough to understand. Basically $threadID is a number, and it's looking through the database to find all the posts with that threadID on them . Let's pretend $threadID is 1. That means all posts with a threadID of 1 will show up on the thread.

That replyID (the post ID) is what I need in this include file.

Something like this:

PHP Code:
$result mysql_query("SELECT * FROM $DBpostsTable WHERE threadID = '$threadID' ORDER BY replyID");
  while(
$row mysql_fetch_array($result))
    {
       <
form   action='edit.php?r=".$row['replyID']."$replyID'   method='post'>
      <
input class='imgsubmit' type='image'   src='images/edit.png' alt='Edit'>
      </
form>
    } 
Now the above works! But I want the part with the form to be in the config file so I don't have to keep changing EVERY SINGLE PAGE using that 'algorithm' (I guess) to make 1 little change.

Any help would be appreciated

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-13-2010, 05:56 PM Re: Using variables of the current page in an include ???
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You mean;

Just like every forum does with posts?

Every blog, CMS etc etc does with comments?


Quote:
But I want the part with the form to be in the config file
Put it there then!

or did I miss something??
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-13-2010, 06:58 PM Re: Using variables of the current page in an include ???
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Yes, sorry

I tried to sort of 'simplify' my problem, by posting only code snippets, not the whole code. I can post the whole code here if you want (well, the part that matters).

Here it is:

config.php
PHP Code:
...
$postOptions "
<form action='edit.php?r="
.$row['replyID']."' method='post'>
<input class='imgsubmit' type='image' src='images/edit.png' alt='Edit'>
</form>"
;
... 
index.php
PHP Code:
<?php include("config.php");?> 
...Head section...
<?php
  $findCategory 
mysql_query("SELECT * FROM $DBcategoryTable");
  
$newresult mysql_fetch_array($findCategory);
  
$findCategory2 mysql_query("SELECT subjectline FROM $DBthreadTable WHERE threadID= '$threadID'");
  
$newresult2 mysql_fetch_array($findCategory2);
  
$findSubject mysql_query("SELECT subjectline FROM $DBthreadTable WHERE threadID= '$threadID'");
  
$subject mysql_fetch_array($findSubject);
  echo 
"<p class='forbox'><a href='index.php'>Home</a> &rarr; <a href='$curURL?cID=$categoryID'>".$newresult[1]."</a> &rarr; <a href='$curURL?threadID=$newresult2[0]'>$newresult2[0]</a></p>";
  
$result mysql_query("SELECT * FROM $DBpostsTable WHERE threadID = '$threadID' ORDER BY replyID");
  echo 
"<table cellpadding='0' cellspacing='0' width='100%'>";
  echo 
"<h1>$subject[0]</h1>";
  while(
$row mysql_fetch_array($result))
    {
      echo 
"<tr class='fullpost'><td class='forumauthor' width='5%' valign='top'>";
      
$MIO mysql_query("SELECT * FROM members WHERE username = '".$row['author']."'");
      while(
$mRow mysql_fetch_array($MIO))
    {
      echo 
"<img class='avatar' src='avatars/".$mRow['username'].$mRow['avatar'].".png' alt='' /><br />".$mRow['username']."<br />";
      echo 
"Posts: ".$mRow['postcount']."<br />";
    }
      echo 
"</td><td class='forumpost' valign='top'>".$row['replyContent']."<br /><div class='postoptions'>$postOptions</div><hr />";
      
$MIO mysql_query("SELECT sig FROM members WHERE username = '".$row['author']."'");
      while(
$mRow mysql_fetch_array($MIO))
    {
      echo 
$mRow['sig'];
    }
      echo 
"</td>";
      echo 
"</tr>";
?>
:|. Hopefully that's enough .

Ok so basically the bold part is what I'm having trouble with:
echo "</td><td class='forumpost' valign='top'>".$row['replyContent']."<br /><div class='postoptions'>$postOptions</div><hr />";

As you can see, it echoes out the content of the reply (this is a forum), and then it's supposed to give a few lines, then have a div called 'postoptions' with $postOptions in it. That all displays fine and dandy. Except when you click the submit button (an image), instead of leading you to a page called edit.php?r=".$row['replyID']." (Would show up as edit.php?r=2 [2 being a random number I made up]). But it just goes to edit.php?r=. That's it. There is no ".$row['replyID'].". Why isn't that carrying over?
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 07-13-2010, 07:33 PM Re: Using variables of the current page in an include ???
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I think I understand, you want postoptions to carry the HTML and dynamically drop the replyid in the string.

With you adding the var in the config file, the $row var is not yet defined. Your best solution is to use a formatted string instead.

Example Config:
PHP Code:
$postOptions "
<form action='edit.php?r=%d' method='post'>
<input class='imgsubmit' type='image' src='images/edit.png' alt='Edit'>
</form>"

Example Use:
PHP Code:
echo "</td><td class='forumpost' valign='top'>".$row['replyContent']."<br /><div class='postoptions'>".sprintf($postOptions$row['replyID'])."</div><hr />"
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-13-2010, 08:16 PM Re: Using variables of the current page in an include ???
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Thanks! It works now
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using variables of the current page in an include ???
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48684 seconds with 12 queries