PHP - Get Similar Posts
im trying to run a query which will get posts from the database that have tags similar to the current ones.
Unfortunatly the echoed result isnt displaying as it should. $query = $link->query("SELECT t.*, p.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) WHERE t.t_name = '".decode_url($_GET['t_name'])."' LIMIT 1") or die(print_link_error()); $row = $query->fetch(PDO::FETCH_ASSOC); $tag_query = $link->query("SELECT p_name FROM ".TBL_PREFIX."posts WHERE MATCH (p_tags) AGAINST ('".$row['p_tags']."' IN BOOLEAN MODE) ")or die(print_link_error()); $result = $tag_query->fetch(); foreach($result as $key => $value) { echo 'Name = '.$result[$key]['p_name'].'<br />'; } i have done a dump of result and it shows: Code: [Select] $ => Array (2) ( ['p_name'] = String(12) "File Updates" ['0'] = String(12) "File Updates" ) but there should only be one item in this array(p_name). I dont know where the second is coming from. The query has pulled the right results, it just isnt displaying it right. Similar TutorialsHello, I am looking for a push in the right direction. I would like to be able to view a website that is duplicated on many servers by specifying the IP address. Similar to how one would use the hosts file. I can do this using netcat nc 1.2.3.4 80 Host: example.com GET /contact-us.html <CR><CR> Can someone tell me how I would go about porting this to PHP? I would just like to set up a small page on my webserver where I can enter the domain and IP address and have the page displayed back to me. Thanks Colin I'm pretty sure there isn't, but I was wondering if there was a php function that would return partial matches similar to MySQL's LIKE, I've been searching for a while and haven't found one. If not, is there a class or something that someone knows of that will accomplish a like of search or a string comparison? I want to be able to compare two variables and return one of three results - Exact Match, Partial Match, No Match. I suppose regex may do the trick but I'm a complete novice when it comes to regex and I have no idea where to even begin. Thanks for any suggestions. How can I check if an array contains two items that are the same? For example ("apples", "bananas", "oranges") returns false But ("apples", "bananas", "bananas") returns true hi My first language is not english so i hope you bear it i am new to php am am making my shopping Cart as my web engineering course i have made everything i all want to know how to i show similar products when a user click on any product details it open new page and shows a detail of that page i want to show similar products list below to details so can any tell me how to do it plzz kindly see the pic in atttachment i have posted snap shop of my page i put similar product statically i want to show it dynamically from tha data base kindly answer please regards Hello everybody, I have a question I've been striving with for a while and I was wondering if someone more experienced than me could have an answer or point me in the right direction. I'm building a website with an integrated forum what is the best system to detect and return which post is 'new', which one is 'hot' and which one hasn't changed from the user's last visit? In my user's table I store the last time the user logged in and the last time the user browsed a page... but it seems to be not enough to accurately return the information I need... Any suggestion is appreciated. Thanks. are all of the following same, or some same or all different: $variable="" $variable=0 $variable=NULL and which of the above will satisfy if(empty($variable)) { blah!; } How to COUNT the number of records (pulled from a db)which contains the word "APPROVED". This code doesn't work though. $result1; $result2; $result3; $approvedApplicants = COUNT($result1=='Approved', $result2=='Approved', $result3=='Approved') echo ($approvedApplicants) Hello, I need to be able to find what is inbetween 2 values in a string of text. For example, <?php $string="Hello and welcome to the site. Click [link]welcome.php[/link] here to continue to the site"; ?> So I need some method of searching the string to see what values are in between the [link] and [/link] which I will then deal with in my own way. I have a feeling that I could do this with explode, but I'm not really sure. Any advice? Thanks in advance I have a brain twister in a script i'm working on. It have a multidimensional array that hold values to populate a google charts js script. To make it work as I plan I need to merge the data from similar arrays together. I'll give an example and hopefully it will make more sense. Also, this page is being loaded over ajax so, the faster/smaller the better. Example Array: Code: [Select] Array ( [0] => Array ( [item] => 1 [quant] => 2 [price] => 12.5 [day] => 18 [onl] => ) [1] => Array ( [item] => 1 [quant] => 2 [price] => 12.5 [day] => 18 [onl] => ) [2] => Array ( [item] => 1 [quant] => 5 [price] => 12.5 [day] => 17 [onl] => 1 ) [3] => Array ( [item] => 1 [quant] => 12 [price] => 12.5 [day] => 19 [onl] => 1 ) [4] => Array ( [item] => 1 [quant] => 4 [price] => 12.5 [day] => 21 [onl] => ) ) So since array 0 and 1 both have data from sales on the 18th for the same item I would want to merge them into a single array and leave all others in the parent array the same. I apologize in advance if this doesn't make sense, I've been working too many hours. X| If anyone knows of a good solution for this or perhaps a better approach, that would be great. Thank You, E This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=350182.0 Hi Folks, i have been at this for ages and its now depressing me as i cannot figure out why i cant get it to work. I am using a re-hashed version of a facebook style wall post system where it limits the amount of replies, you click a button and gets the next set and so on until there are no more results to get. The original script runs ok but is not really suitable for what i need So to my script which is based loosley on the same principal. Ok i have a veiwmember.php page which uses pagination to limit the amount of wall posts to 5. I have included the various javascript files jquery and another which is needed. The function used is this one: Code: [Select] <script type="text/javascript" src="jquery.livequery.js"></script> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript"> //more records show $('a.more_records').livequery("click", function(e){ var next = $(this).attr('id').replace('more_',''); $.post("data.php?show_more_post="+next, { }, function(response){ $('#bottomMoreButton').remove(); $('#posting').append($(response).fadeIn('slow')); }); }); </script> The php code in veiwmember.php that gets the wall posts is: Code: [Select] Pagination code here <?php $getwallposts= ("SELECT * FROM wallposts WHERE recipientid='$memberid' ORDER BY id DESC LIMIT $offset, $rowsperpage"); $result = mysql_query($getwallposts,$con); while ($row2 = mysql_fetch_assoc($result)) { $messageid= $row2['id']; $senderid= $row2['senderid']; $wallpost= $row2['wallpost']; $timesent= $row2['timesent']; $timestamp = strtotime($timesent); $likes= $row2['likes']; $getname= ("SELECT fname, lname, image1 FROM memocp WHERE unid='$senderid'"); $nameresult= mysql_query($getname,$con); while ($rowws = mysql_fetch_array($nameresult)) { $fname= $rowws['fname']; $lname= $rowws['lname']; $wallpostprofilethumb= "{$rowws['image1']}"; if (empty($wallpostprofilethumb)) {$wallpostprofilethumb= "noimage.png";} } ?> <div class="wallpost"><div class="from"><div class"profilethumb"><img src="profilethumb/<?php echo $wallpostprofilethumb; ?>"></div><a href="veiwmember.php?membid=<?php echo "$senderid"; ?>"><?php echo "$fname $lname"; ?></a></div><div class="postbody"><?php echo txt2link($wallpost) ?><div class="timesent"><?php echo date('l jS F Y @ H:i a', $timestamp); ?></div></div><div class="likes"><form action="like.php" method="post"><?php if (isset($_GET['currentpage'])) {$currentpage= $_GET['currentpage']; echo "<input name=\"currentpage\" type=\"hidden\" value=\"$currentpage\">";} ?><input name="messageid" type="hidden" value="<?php echo "$messageid"; ?>"><input name="base" type="hidden" value="<?php echo "$memberid"; ?>"><input name="like" type="image" src="ima/like.jpg"><?php echo " $likes people like this"; ?></form></div></div> <?php include_once('data.php'); ?> <?php } rest of pagination The pagination sort of works, but only displays one result per page when it should show 5 results plus how ever many replies, but i can sort that out later, would prefer to get the replies working first. You will see that data.php is included which gets the replies to the wall posts. It should limit the amount of replies shown to five, and then if there is more, it will show a link to get more. If that link is clicked it should get the next five results and show them. However it shows the first five and the link if there are more results, but if the link is clicked, nothing happens. data.php Code: [Select] require ("database.php"); $next_records = 5; $show_more_button = 0; if(isset($_REQUEST['show_more_post'])) // more posting paging { // button has been clicked so we need to get next set of results $next_records = $_REQUEST['show_more_post'] + 5; $result = mysql_query("SELECT * FROM wallreplies2 WHERE messageid='$messageid' ORDER BY wallreplyid DESC limit ".$_REQUEST['show_more_post'].", 5"); // see if there are any more replies to get $check_res = mysql_query("SELECT * FROM wallreplies2 order by wallreplyid DESC limit ".$next_records.", 5"); $show_more_button = 0; // button in the end $check_result = mysql_num_rows($check_res); if($check_result > 0) { // if there any more results counted the button needs to be shown $show_more_button = 1; } } // if the button hasnt been clicked we need to get the first results else { // lets count the number of results that exist $countreplies= mysql_query("SELECT * FROM wallreplies2 WHERE messageid='$messageid'"); $countresult= mysql_num_rows($countreplies); // if there are more than 5 results if ($countresult > 5) { // the button needs to be shown $show_more_button = 1; } else { // if there are 5 or less replies in total, dont show the button $show_more_button = 0;} //there are only 5 or less replies to get so get the first results $result = mysql_query("SELECT * FROM wallreplies2 WHERE messageid='$messageid' ORDER BY wallreplyid DESC limit 0,5"); } //$replyresult = mysql_query($result,$con); while ($roww = mysql_fetch_array($result)) { $wallreplyid= $roww['wallreplyid']; $sendid= $roww['senderid']; $wallreply= $roww['wallreply']; $time= $roww['timesent']; $Timestamp = strtotime($time); $like= $roww['likes']; $getreplynames = ("SELECT fname, lname, image1 FROM memocp WHERE unid='$sendid'"); $nameresults = mysql_query($getreplynames,$con); while ($roww = mysql_fetch_array($nameresults)) { $fnames= $roww['fname']; $lnames= $roww['lname']; $wallreplyprofilethumb= "{$roww['image1']}"; if (empty($wallreplyprofilethumb)) {$wallreplyprofilethumb= "noimage.png";} } ?> <div class="wallreplies" id="record-<?php echo"$wallreplyid"; ?>"> <div class="wallreplywrap"> <div class="wallfrom"> <div class"profilethumb"><img src="profilethumb/<?php echo $wallreplyprofilethumb; ?>"></div> <a href="veiwmember.php?membid=<?php echo "$sendid"; ?>"><?php echo"$fnames $lnames"; ?></a> </div> <div class="wallmessbody"><?php echo txt2link($wallreply) ?></div> <div class="timesent"><?php echo date('l jS F Y @ H:i a', $Timestamp); ?></div> <div class="likes"><form action="like2.php" method="post"><?php if (isset($_GET['currentpage'])) {$currentpage= $_GET['currentpage']; echo "<input name=\"currentpage\" type=\"hidden\" value=\"$currentpage\">";} ?><input name="messageid" type="hidden" value="<?php echo "$wallreplyid"; ?>"><input name="base" type="hidden" value="<?php echo "$memberid"; ?>"><input name="like" type="image" src="ima/like2.jpg"><?php echo " $like people like this"; ?></form> </div> </div> </div> <?php } if($show_more_button == 1){ echo "<div class=\"bottomMoreButton\"> <a id=\"more_$next_records\" class=\"more_records\" href=\"javascript: void(0)\">Get more replies</a> </div>"; }?> <div class="wallreply"> <form action="wallreply.php" method="post"> <input name="sendrid" type="hidden" value="<?php echo "$loginuniqid"; ?>"> <input name="messageid" type="hidden" value="<?php echo "$messageid"; ?>"> <input name="base" type="hidden" value="<?php echo "$memberid"; ?>"> <?php if (isset($_GET['currentpage'])) {$currentpage= $_GET['currentpage']; echo "<input name=\"currentpage\" type=\"hidden\" value=\"$currentpage\">";} ?> <textarea class="newwallpostreply<?php echo $i++ ; ?>" name="wallreply" autocomplete="off" maxlength="1000" placeholder="Reply"></textarea> <span class="wallreply-holder<?php echo $p++; ?>"> <div class="button_block"> <input type="submit" class="post" value="Post"> <input type="submit" class="cancel" value="Cancel"> </div> </span> </form> </div> I know its a lot of info there, but if anyone can see the problem i would be greatful. Hey! So, I don't know if this is the current section, couldn't really decide on what section/board to post it, so ..
I've got a code that I got from a friend of mine (it was a gaming website (a game server), but he shut it down, I asked for some scripts, he sent me the whole site ..). I got all other scripts correctly, but I do not know how to get this Last Forum Posts to work (IP.Board). I've got the SEO set up as it should and everything, doesn't work.
When I use this
<?php $_handlerForum = new mysql("Forum","localhost","*********_fqipb2","*********_fqipb2","password"); $topics = $_handlerForum->fetch("SELECT `tid`,`title`,`last_post`,`title_seo`,`last_poster_name` FROM `topics` ORDER BY `last_post` DESC LIMIT 0,3;",array()); $content = ""; foreach($topics as $topic) { $content .= "<a href='http://website.com/forum/index.php?/topic/".$topic['tid']."-".$topic['title_seo']."' target='_blank'>".$topic['title']."</a><br /> <small class='dim'>".$topic['last_poster_name']." - ".date("H:i F d, Y",$topic['last_post'])."</small><hr style='margin: 5px 0px;' />"; } return $content; return "Under Construction"; ?>I get this error Fatal error: Class 'mysql' not found in /home/***/***/***/public_html/extra/forum.php on line 2Thought that the problem was "new mysql" (on line 2), so I put in mysql_connect, still get an error. Can anyone help? Hi there, I have a piece of code that takes all posts with the category of 'model' and puts it on the models page. It then displays the post as a gallery using fancy box. The problem is I want all posts with the category of 'faces' to go on the faces page, but at the moment they are appearing on both pages. Here is the code I have. Any help will guarantee a donation as I am at my wits end trying to figure this out. Code: [Select] <?php global $post; $args = array( 'numberposts' => 8, 'offset' => 0, 'category' => 'models', 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish' ); $posts_array = get_posts( $args ); $x = 1; // track model foreach( $posts_array as $post ) { setup_postdata($post); ?> <div id="model-thumb"> <?php $arg2 = array( 'post_type' => 'attachment', 'numberposts' => -1, 'order' => 'ASC', 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($arg2); if ($attachments) { $i = 1; // track images foreach ( $attachments as $attachment ) { $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'full' ); if ($i == 1) { // Get thumbnail info to display with second image $img1src = $image_attributes[0]; $img1w = $image_attributes[1]; $img1h = $image_attributes[2]; } elseif ($i == 2) { // Display thumbnail with link to second image ?> <a class="allModels" rel="gallery<?php echo $x; ?>" href="<?php echo $image_attributes[0]; ?>" ?><img src="<?php echo $img1src; ?>" width="<?php echo $img1w; ?>" height="<?php echo $img1h; ?>"/></a><br /><p><?php the_content();?></p></div> <?php } else { // Other images ?> <div style="display:none;"><a class="allModels" rel="gallery<?php echo $x; ?>" href="<?php echo $image_attributes[0]; ?>"><img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>"/></a></div> <?php } $i++; // Increase image count } } $x++; // Increase model count } ?> I have made a website that deals with the sales of different products. It handles the total sales of a specific product. One of the aspects of the website is that it can change the current sales data of the products. At the moment I can change the sales figures fine however I have to click the submit button once and then physically refresh the page for it to change the data in the table. Is there a way that I can automatically refresh the page once the submit button is pressed? I have tried using headers for example: Code: [Select] if (!empty($_POST['NSales'])) { header('location: currentpage.php'); } however this just constantly refreshes the page. Any help would be greatly appreciated Hello everybody, I'm trying to write some code similar to Odesk.com or DMOZ.ORG. I need to count the number of listings in each category. Look here "http://ibatty.org/browse.php" to get a better idea of what I'm doing. That is the page I'm trying to add this function to. I've been having major issues with the COUNT function. Code: [Select] $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='billboards'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) { echo $row[COUNT(category)]; } As you can see this works, but I'm trying to add State, Area code and Zip functuality to search through the data more precisely. This has been giving me problems though and the way I currently have it setup . . . I'd have 25+ SELECT COUNT() querys going on 1 page. (I don't know if that is very good?) 5$ via paypal to whoever can help me solve this. If I did not explain what I needed very well, please ask questions for me to clarify. Thank you in advance I need to display multiple files that have a similar file name, but there are timestamps added to the filename once its been modified. What could I use in PHP to display all these files? Right now I use a $path variable that looks into a SQL table to build the path to the folder that the files reside in.. ELSEIF($Recordmyrow['Applicatio'] == "pdf file") { IF($securityvalue != "P"){$display = false;} IF(file_exists(substr($path, 5))){} ELSE{$column4 = "<A href='javascript:mbox();'>UNAVAILABLE</A>";} } So there is a file called file1.pdf then another one called file1.mmddyyyy.pdf My code shows file1.pdf but not file1.mmddyyyy.pdf Is there some kind of wildcard I can use to get it to show all the files if they exist? Hi all. This seems like a pretty basic function but I can't work it out. I'm developing a WordPress site and want to list posts (products) by category. I'm using Advanced Custom Fields and have set up the taxonomy of 'category'. I just want to produce a heading for that category and then list all of the posts with that category assigned. Please see below functions.php excerpt and section-archive.php excerpt. Can anyone please help??? Massive good karma if you can. ----------------------- functions.php -------------------------------------- //Assign Category to Products
function taxonomy ()
$args = array (
}; ?> ------------------------- section-archive.php ------------------------------------------------ <?php if(have_posts()):while(have_posts()): the_post();?>
****** if product category= this ***** Category heading ****** Posts ******* Else ****** if product category= this2 ***** Category heading ****** Posts **** etc
<div class="prod-listing">
How can I prevent the less than and greater than signs in the username field, and message on the post? As well as slashes. / \. Code: [Select] <form method="post" action="" id="reply"> <script type="text/javascript"> function hi(id){ var val = id.options[id.selectedIndex].value; var text = id.options[id.selectedIndex].text; if (val.length != 0){document.getElementById('user').value = text;hide('passrow');} else { document.getElementById('user').value = ''; document.getElementById('passrow').style.cssText = ''; } } </script> <div id="userpass" style="background: #000;"> <table style="border: 2px solid #252564; background: #1F1F5D;" width="100%" cellpadding="0" class="quick_userpass"> <tr> <td background="/images/bg3.jpg" height="26px"><font face=arial size=2 color="white"> <b>Your Name or Nickname</b></td> </tr> <tr> <td><input size=50 name="user" id="user" value="" style="margin-left: 10px;"></td> </tr> <tr><td background="/images/bg3.jpg" height=26px></td></tr> </table> <div id="passrow" style=""> <p> <table width=100% cellpadding=0 class="quick_userpass" style="border: 2px solid #252564; background: #1F1F5D;"> <tr><td background="/images/bg3.jpg" height=26px style=""><font face=arial size=2 color="white"> <b>Password (optional)</b></td></tr> <tr><td style=""><input size=50 name="pass" id="pass" type="password" style="margin-left: 10px;" value=""></td></tr> <tr><td background="/images/bg3.jpg" height=26px></td></tr> </table> </p> </div> <p> <table width=100% cellspacing=0 cellpadding=4 class="quick_userpass" style="border: 2px solid #252564; background: #1F1F5D;"> <tr bgcolor="#121236"><td><font face=arial size=2 color="white"><b>Enter your message here</b></font></td></tr> <tr><td><center><textarea id="quickreply" name="message" rows=10 cols=50 wrap="VIRTUAL" ></textarea></center></td></tr> </table> <div id="preview" style="display: none;"></div> </p> <br /> <center> <font face=arial size=2>When you're happy with your message, click:</font> <div id="javano"><input type="submit" value=" Post Message "></div> </center> <input type="hidden" name="tid" value="<?php echo $_GET["tid"];?>" /> </div> </form> That is the code I'm using for User/Pass/message fields. hey I am not usually in this php forum, I am usually around html/css but a task arose and I figure since this forum uses smf it would be a perfect place to ask. Not saying you are all smf experts though. My question is how do I display the latest posts for smf in a page thats not a forum page. Like On my index page I want to display the latest posts on the forum. Help anyone? i have a problem..my posts are showing up like this: July 6: post message July 6: post message July 6: post message im trying to get it like this: July 6: post message post message post message how do i group them like this in all in one post? |