Jump to content

EchoFool

Members
  • Posts

    1,074
  • Joined

  • Last visited

Everything posted by EchoFool

  1. Argh right. Looks like they have thought of just about everything! Thanks poco and Ken! SOLVED
  2. How will it know that it must match the same ThreadID as the primary key that is created upon insert on the first query? My first query table has a "ThreadID" field which when an insert occurs.. it auto increments. This then is the ID, if i use mysql_insert_id... won't it just pick any random number?
  3. Ok, i have a major problem here. Completely stuck as to how this works. I am designing a forum, now say the user creates a thread. This is then inserted into the thread table ...see below: <?php $UPDATE = mysql_query("INSERT INTO forums (Catergory,ThreadName,ThreadStarter,CreatedOn,LastPost, LastUser) VALUES ('$Category','$Subject','{$_SESSION['Current_User']}','$Date','$Date','{$_SESSION['Current_User']}')") Or die(mysql_error()); ?> Now the issue I have here is that i need to insert the "$Post" that the user made with the thread (obviously). Now I am sure you can see where this is going... as I insert a thread it creates a ID, but to insert a post i need this thread ID ... only I don't know how i can get the ID of the thread the user just created because theres no real way of searching for the ID .. you get me ? This is the real script... so you can see my problem: <?php $Post = mysql_real_escape_string($_POST['letter']); $Subject = mysql_real_escape_String($_POST['Subject']); //CREATE THREAD $UPDATE = mysql_query("INSERT INTO forums (Catergory,ThreadName,ThreadStarter,CreatedOn,LastPost, LastUser) VALUES ('$Category','$Subject','{$_SESSION['Current_User']}','$Date','$Date','{$_SESSION['Current_User']}')") Or die(mysql_error()); //POST FOR THE THREAD $UPDATE2 = mysql_query("INSERT INTO posts (Postmessage,postedby,CreatedOn,ThreadID) VALUES ('$Post','{$_SESSION['Current_User']}','$Date','---//not possible surely?---')") <?php Or die(mysql_error()); ?> Relating to this part in the second query "---//not possible surely?---" , so how can i get the ThreadID that was just created in order to post this at the same time. Is it possible to select threadID that is created in the first query in the forums table at the same time as the insert so it gets the correct ID? Hope some one can help me!
  4. Yeh i already have the query made and already have it looped but i need a way to find out that the first row that is looped is the first if you get me so that it will show: id | name | is first 23 | bleh | this is first post 42 | fefw | 56 | fsffs | like that is what I want it to work out. That the first row that comes out of the loop is the first and so will echo the statement "this is the first post"
  5. If i do query to get all rows for a specific WHERE clause and order it by ID. What i do then is while loop the rows. How ever on the "first" loop i.e the first row being echo'd i want it to say "This is the first row" and the rest do not have it. What i thought was to "Find lowest ID" of the selected rows" ... as it is ordered by ID ... that would surely suggest the lowest ID is the first of the rows right? Can it be done solely with the main query and php or will i need an additional query in the while loop to check if the post is the first or something?
  6. Yeh but then i get this: 0 1 2 3 I would rather some how get rid of the 0 so it starts on 1...if possible? =/
  7. Me again... i am wondering if some one could help explain how i can add to my pagination. It works a treat... only I only know how to create a "Next Last" "First Previous" option.. But what i am looking for is: First Previous 1 2 3 [4] 5 6 Next Last (Assuming.. that in this situation.. the user is on page 4.) I do not know how to make numbered pages display, im sure its a mathematical equation in a while loop of some sort ?.... This is what I am using for my script: <?php //pagination test //pagination if (isset($_GET['Page'])) { $Page = mysql_real_escape_string($_GET['Page']); If($Page == '' OR !(is_numeric($Page))){ $Page = 1; } } else { $Page = 1; } $Check = mysql_query("SELECT ThreadStarter FROM forums WHERE Catergory='$Catergory'") Or die(mysql_error()); $rows_per_page = 15; $TotalRows = mysql_num_rows($Check); $LastPage = ceil($TotalRows/$rows_per_page); //numeric validation $Page = (int)$Page; if ($Page < 1) { $Page = 1; } elseif ($Page > $LastPage) { $Page = $LastPage; } $Limit = 'LIMIT ' .($Page - 1) * $rows_per_page .',' .$rows_per_page; if($Limit < 0) { $Limit = 0; } $Get = mysql_query("SELECT CreatedOn,ThreadID,ThreadStarter,ThreadName,LockedSticky,LastPost,LastUser FROM forums WHERE Catergory='$Catergory' ORDER BY LastPost DESC $Limit ") Or die(mysql_error()); //--------------------------------------------------------- If($TotalRows > 15){ if ($Page > 1) { $PrevPage = $Page-1;?> <li><a class=forums publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$PrevPage?>">Previous</a></li> <li><a class=forums href="publicforum.php?Catergory=<?=$Catergory?>&Page=1">First</a></li> <?php}ElseIf($Page == 1){ $NextPage = $Page+1;?> <li><a class=forums href="publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$NextPage?>">Next</a></li> <li><a class=forums href="publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$LastPage?>">Last</a></li> <?php} ElseIf ($Page == $LastPage) { $PrevPage = $Page-1; ?> <li><a href="publicforum.php?Catergory=<?=$Catergory?>&Page=1">First</a></li> <li><a href="publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$PrevPage?>">Previous</a></li> <?php } } ?>
  8. Ok thats fixed the error! Thankyou Chris.. lets just hope it works SOLVED
  9. EchoFool

    Help

    <?php mysql_connect(mysql,$name,$password) or die(mysql_error()); @mysql_select_db($database) or die( "Unable to select database"); // // CHANGE QUERY TO GRAB THE ID // $query = "select * from test"; $result=mysql_query($query) or die (mysql_error()); $num=mysql_num_rows($result); print_r(mysql_fetch_array($result)); exit(); // debug lines mysql_close(); $i=0; while ($i < $num) { $company=mysql_result($result,$i,"company"); $name=mysql_result($result,$i,"name"); $address=mysql_result($result,$i,"address"); $city=mysql_result($result,$i,"city"); $state=mysql_result($result,$i,"state"); $zip=mysql_result($result,$i,"zip"); $phone=mysql_result($result,$i,"phone"); $acct_num=mysql_result($result,$i,"acct_num"); $email=mysql_result($result,$i,"email"); $start_date=mysql_result($result,$i,"start_date"); $end_date=mysql_result($result,$i,"end_date"); $remind_date=mysql_result($result,$i,"remind"); $lost_password=mysql_result($result,$i,"lost_password"); $lost_password_answer=mysql_result($result,$i,"lost_password_answer"); $to = "$email"; $subject = "Your Subscription is about to expire"; $message="This mail was sent to you because your subscrption with Affordable Everything will expire on $end_date.\nYou can login to your account and use the link at the top of the page to renew your registration. If you let your subscription lapse, Your information and ads you have placed will be deleted and you will have to reregister and enter them all again."; $headers = "From: subscriptions@affordit.us"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ++$i; } ?> Try that... you may want to put Error report ALL on ... just to get a bigger answer of errors.
  10. I have attempted my first pagination script but get an error on some syntax... was wondering if you would be kind enough to show me what i have done wrong.. My error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-15,15' at line 1 This is my pagination script: <?php $Check = mysql_query("SELECT ThreadStarter FROM forums WHERE ThreadID='$Thread' && Catergory='$Catergory'") Or die(mysql_error()); //pagination test $rows_per_page = 15; $TotalRows = mysql_num_rows($Check); $LastPage = ceil($TotalRows/$rows_per_page); //numeric validation $Page = (int)$Page; if ($Page < 1) { $Page = 1; } elseif ($Page > $LastPage) { $Page = $LastPage; } $Limit = 'LIMIT ' .($Page - 1) * $rows_per_page .',' .$rows_per_page; $query = mysql_query("SELECT ThreadStarter,ThreadName,LockedSticky FROM forums WHERE ThreadID='$Thread' && Catergory='$Catergory' $Limit") Or die(mysql_error()); //--------------------------------------------------------- ?> Help is much appreciated!
  11. How can i use a function on a variable in a while loop? Because at the moment in simple logic terms i have: <?php While { $Message = $row['PostText']; function BBCode($BB){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[Quote]" => "<div class='quotetop'>QUOTE</div><div class='quotemain'>TestTest", "[/Quote]" => "</div>"); $Message = str_replace(array_keys($BBCode), array_values($BBCode), $BB); return $Message; } ?> <?$newString = BBCode($Message); echo $newString;?> } But now i get this error: Fatal error: Cannot redeclare bbcode() (previously declared in C:\xampp\htdocs\publicforum.php:464) in C:\xampp\htdocs\publicforum.php on line 464 I can't put it "before" the while loop because then $Message is undefined right? So what do i do now?
  12. Yeah i tried that but it didn't work....see if it works for you: <SCRIPT language="JavaScript"> // Surrounds the selected text with text1 and text2. function surroundText(text1, text2, textarea) { // Can a text range be created? if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange) { var caretPos = textarea.caretPos, temp_length = caretPos.text.length; caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2; if (temp_length == 0) { caretPos.moveStart("character", -text2.length); caretPos.moveEnd("character", -text2.length); caretPos.select(); } else textarea.focus(caretPos); } // Mozilla text range wrap. else if (typeof(textarea.selectionStart) != "undefined") { var begin = textarea.value.substr(0, textarea.selectionStart); var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart); var end = textarea.value.substr(textarea.selectionEnd); var newCursorPos = textarea.selectionStart; var scrollPos = textarea.scrollTop; textarea.value = begin + text1 + selection + text2 + end; if (textarea.setSelectionRange) { if (selection.length == 0) textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length); else textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length); textarea.focus(); } textarea.scrollTop = scrollPos; } // Just put them on the end, then. else { textarea.value += text1 + text2; textarea.focus(textarea.value.length - 1); } } </SCRIPT> <?phpIf(!isset($_GET['italics'])){?> <li><a href="" onclick="surroundText('[i]', '[/i]', document.getElementById(text)); return false;">Italics</a></li> <?php}ElseIf(isset($_GET['italics'])){?> <li><a href="publicforum.php?Catergory=<?=$Catergory?>&Thread=<?=$Thread?>&italics2">Italics ***</a></li> <?php}?> <textarea name="TextArea1" id="text" rows="14" cols="60"></textarea><br> <input type="submit" name="Button1" value="Post Reply">
  13. Just wondering if any one could explain how phpfreaks allows you to insert tags around text by pression the buttons above the text area and not refresh the page when it inserts it to the text? Like if i put this sentence and then press the quote button it inserts the [ quote ] ? I been using sessions which is a bit of pain when users go to a different post and session is still created meaning it will still show their last post when they want to type out a new one... Hope you can explain it a bit.
  14. Wait its working now! Thanks alot guys ! [sOLVED]
  15. Ok it now echo's but it won't put the tags around it.. this is my page source of the echo: <tr> <td colspan="2" valign="top" bgcolor="#ecfff7"><br> Bold not bold. </td> </tr> Notice there is no <b> </b>
  16. Ok that didn't echo anything .. but i don't get the undefined variable error, so it must be there but won't display im guessing? My current code: <?php function BBCode($BB){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>"); $Message = str_replace(array_keys($BBCode), array_values($BBCode), $Message); return $Message; } $newString = BBCode($Message); echo $newString;?>
  17. So i have echo $Message? Because i tried that also, and all i got was the text but not <b> tags around it when i looked at the page source to check.
  18. I have a function for bbcode but when i echo the function it comes out blank! Not sure what i did wrong... This is my code: <?php $Message = '[b] Bold [/b] not bold.'; function BBCode($BB){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>"); $Message = str_replace(array_keys($BBCode), array_values($BBCode), $Message); return $Message; } Echo $BB; ?> Could some one test this tell me if it works for me cos when i echo $BB nothing happens.
  19. yeah my bad forgot i had that there when i was pasting it across.. have updated it, although that wasn't what was causing the problem, as the query wouldn't load the posts anyway... My tables are like this: forum table posts table Hope you can help
  20. I am building myself a forum which is pretty hard going. I have a query which is loading the posts for the relevant thread. Now the two variables in determining which thread the user is viewing is "catergory" (where the thread is.. such as offtopic/general discussion ) etc And "thread" (the ID of the thread). Now the variables work but the query does not load the posts related to the thread. Was hoping some one may be able to see what i am missing.... This is what i got: <?php $Get = mysql_query("SELECT posts.* FROM posts,forums WHERE forums.Catergory='$Catergory' AND forums.ThreadID='$Thread' AND posts.Status!='2' AND posts.ThreadID='$Thread' ORDER BY posts.PostID ASC") Or die(mysql_error()); If(mysql_num_rows($Get) < 1){ Echo 'There was an error!'; } ?> At the moment I am always getting the "There was an error". Not sure why it wont let find the correct posts ...
  21. So like this: <?php for($Array = 0; $Array < count($_POST['Checkbox']; $Array++){ $ItemID=$_POST['Checkbox']; $Quantity=$_POST['Quantity']; } ?> Some thing like that?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.