PHP - Adding Query String To Any Url
Is it possible to add a query string for example some_var=jk84 to any sort of link be it, http://www.website.com , http://www.website.com/?some_id=4, or http://www.website.com/post=45&category=9 or http://www.website.com/somepost/ ?
While adding that extra query string how can I make sure I'm not affecting the website's content or causing some script error? Similar TutorialsI have seen somewhere that you can add to a string like so $var = "text"; or $string ="var"; &$var = "text"; it is the latter that I am wanting to know more about. Hi, I currently have a string with some values in it: $a_random_string="some random text, goes here - $123<br>some more random text goes here - $53 (text 123 )<br>ANother line of text - $126"; Now I want to add all the values that have a '$' before the value eg; $123. So in this case I would end up with: 302 How would I do this? Thanks, mme I have a php line like: echo "<p><b>Tags: </b>" . $row['tags'] . "</p>";
it looks like this on web page: how do i add hyperlink to each keyword like: Tags: <a href='category/keyword1'>keyword1</a>, <a href='category/keyword2'>keyword2</a>, <a href='category/keyword3'>keyword3</a>,...
I have a file containing lines (I mean elements separated by <br>). How I can put these lines into an array, but only those which has a given phrase. Example file Code: [Select] This is the first line<br> Second line is here<br> something else<br> something else<br> something more<br> I want to catch only lines which contain the word "something" and make an array. I have been becoming more and more familiar with PHP over the past few months, but this problem stumps me. How can I take a string of words separated by spaces taken from an XML feed (example: word1 word2 word3 word4) and turn it into something like this: <a href="word1">word1</a> <a href="word2">word2</a> ... and so on. This has to be done on the fly, since it is taking the words from the XML feed, they change depending on the page. I want them to be in a vertical column, and be able to link each one to the search page for that word, so each link has to be different. An even more in-depth problem, how can I sort it then so that there are multiple columns if necessary, say one page only has 3 words, but another has 50. How can I split them up into multiple vertical columns, say with 10 words in each? Have I confused anyone yet? Hi, This is probably very easy for someone who knows how but I cant seem to get it working. Can someone please tell me how I can alter this query to select a 'WHERE gender = female' so instead of picking a random user it picks a random female user ? Code: [Select] $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `users` "); $offset_row = mysql_fetch_object( $offset_result ); $offset = $offset_row->offset; $user1b = mysql_query( " SELECT * FROM `users` LIMIT $offset, 1 " ); $user1= mysql_fetch_array($user1b); Also, would it be easy to modify it so it picks a second random user that isnt the same as the first user ? so I end up with 2 random females ( $user1 and $user2 ) Many thanks, Scott Hi I have an array of items that I am currently displaying a foreach loop What I'm looking to do, is add a string, to all of items, a part from the last 4: foreach ($pager->getResults() as $items => $item) { echo $item->getName(); //need to add a string to this for the all but the last 4 } Thanks I'm going to create a web page with <iframe> tag & want that the src of <iframe> change as I've made a few attempts at this, but I'm likely not making much sense.... I'm working on how to phrase the question. I had a MySQL database where I used to combine user first AND last names in a single string... I called that string "Member" So if I filtered: www.mysite.com/members.php?Member=Peter It would find and display all Peters: Peter Rabbit and Peter Griffith and Pope Peter. This is what I want. I'm now keeping each name (first and last) in separate strings (as separate variables?), and I am combining them in an array to display on the website: Code: [Select] $First = $First; $Last = $Last; $member = array($Last, $First,); foreach ($Member as $key => $v ) if (!$v) unset ($Member[$key]); $Member = implode(', ', $Member); echo $Member; Now I've lost the ability to search all the members for Peter. So if I filtered: www.mysite.com/members.php?First=Peter ...it would work.... for Peter Rabbit and Peter Griffith, but not Pope Peter I cannot query the entire array? I can no longer check members (first and last names) for Wayne? www.mysite.com/members.php?Member=Peter I'm betting I can, but there's a lot more to it... and 8 hours of Googling haven't helped much. Thanks for listening. ~Wayne Greetings, I need a bit of php coding help. I have a query that gives me results. What I need to do is take those results and, I think, use php to compare the results and add a 1 to the correct section. Example: 3 tables table name- retail_sales id sales_id amount week table name- online_sales id sales_id amount week table name- sales_person sales_id name I have the query that breaks down results by week: week 1 | retail_sales.amount | online_sales.amount What I need is some php code that will then compare the two together and: if retail_sales.amount > online_sales.amount +1 to retail OR if retail_sales.amount < online_sales.amount +1 to online so you would end up with a result like a sports record (6-2) Any ideas Thank you for any help I need to add likes_username to this query and use a DISTINCT on it.
It currently counts how many likes a status has but in the table there are some statuses with multiple likes from the same username.
SELECT s.*, COUNT(l.likes_location_id) AS likeCount FROM stream AS s LEFT JOIN likes AS l ON ( l.likes_location_id = s.stream_id ) GROUP BY s.stream_id ORDER BY s.stream_id DESC LIMIT 50Many thanks, Hello, The query below works well. It pulls information from 3 MySQL tables: login, submission, and comment. It creates a value called totalScore2 based on calculation of values pulled from these three tables. The MySQL tables "comment" and "submission" both have the following fields: Code: [Select] loginid submissionid In the table "submission," each "submissionid" has only one entry/row, and thus only one "loginid" associated with it. In the table "comment," the field "submissionid" could have several entries/rows, and could be associated with multiple "loginid"s. Each time one of the "submissionid"s in "comment" is associated with the same "loginid" that it has in the table "submission," I would like to add this as a factor to the equation below. I would like to multiple instances like this times (-10). How could I do this? Thanks in advance, John $sqlStr2 = "SELECT l.loginid, l.username, l.created, DATEDIFF(NOW(), l.created) + COALESCE(s.total, 0) * 5 + COALESCE(scs.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore2 FROM login l LEFT JOIN ( SELECT loginid, COUNT(1) AS total FROM submission GROUP BY loginid ) s ON l.loginid = s.loginid LEFT JOIN ( SELECT loginid, COUNT(1) AS total FROM comment GROUP BY loginid ) c ON l.loginid = c.loginid LEFT JOIN ( SELECT S2.loginid, COUNT(1) AS total FROM submission S2 INNER JOIN comment C2 ON C2.submissionid = S2.submissionid GROUP BY S2.loginid ) scs ON scs.loginid = l.loginid GROUP BY l.loginid ORDER BY totalScore2 DESC LIMIT 25"; If ($_GET['CODE'] == '1') { $ThreadID = mysql_escape_string($_GET['threadid']); $ForumID = mysql_result(mysql_query("SELECT forum_id FROM ".FORUM_THREADS." WHERE thread_id='{$ThreadID}'", $db), 0, 'forum_id'); $PostText = mysql_escape_string($_POST['replytext']); $IP = $_SERVER['REMOTE_ADDR']; $PostQuery = "INSERT INTO ".FORUM_POSTS." (`user_id`, `thread_id`, `post_text`, `forum_id`, `ip_address`, `timestamp`) VALUES ('{$memid}', '{$ThreadID}', '{$PostText}', '{$ForumID}', '{$IP}' , CURRENT_TIMESTAMP)"; $PostRes = mysql_query($PostQuery, $db); For some reason whenever this query goes through, it also adds a blank result using all the same information but without any $PostTest so essentially it does query: Code: [Select] INSERT INTO ".FORUM_POSTS." (`user_id`, `thread_id`, `post_text`, `forum_id`, `ip_address`, `timestamp`) VALUES ('{$memid}', '{$ThreadID}', '', '{$ForumID}', '{$IP}' , CURRENT_TIMESTAMP) This is the only query that does this part of the code and I can't see why it is adding 2 queries. FORUM_POSTS = constant containing table name. So I have this snippet of code: Code: [Select] $row['ratings'] = ""; $ratingsSQL = $this->ipsclass->DB->query( "SELECT `pid` , `rating` , COUNT(`rating`) as ratings FROM `ibf_ratings` WHERE `pid` = '" . $row['pid'] . "' GROUP BY `rating` "); $i = 0; $ratingshtml = ""; if( $this->ipsclass->DB->get_num_rows( $ratingsSQL ) ) { while( $rrow = $this->ipsclass->DB->fetch_row( $ratingsSQL ) ) { $ratingshtml .= "<div class=\"rate_it_display\" style=\"background-image: url( 'style_images/rate/" . str_replace( ' ' , '' , strtolower( $this->ratings[$rrow['rating']] ) ) . ".png' ) \"> " . $rrow['ratings']. " x " . $this->ratings[$rrow['rating']] . "!</div>"; $i++; } $ratingshtml .= "<a href=\"#\" onclick=\"return RateItExpand( {$row['pid']} );\" style=\"color: #999;\">(list)</a>"; } $row['ratings'] = $this->ipsclass->compiled_templates['skin_topic']->ratings( $row['pid'] , $row['author_id'] , $ratingshtml ); I want to add an if statement to the code so that the ratings won't load unless a user clicks a button at the top of the screen. Can anyone help me with this? I'd be very appreciative. Thanks in advance. Hello everyone, I have this very short script I wrote with help from a book using arrays and the rand function. Basically it changes the images randomly on browser load or refresh. However, I am trying to add an additional, not sure what to call it, a string or another caption for each images. Instead of this being a caption, it will be a link, so a link will appear under each caption that goes to another page when it is clicked on. I tried adding another caption and adding a like to it but getting syntax error. Thanks everyone! Here is the code: Code: [Select] <?php $images = array( array('file' => 'image1', 'caption' => 'Caption 1'), array('file' => 'image2', 'caption' => 'Caption 2'), ); $i = rand(0, count($images)-1); $selectedImage = "graphics/{$images[$i]['file']}.png"; $caption = $images[$i]['caption']; ?> And here is where the images are written to the page: Code: [Select] <div id="stage"> <img src="<?php echo $selectedImage; ?>" alt="Random image" /> <p id="caption"><?php echo $caption; ?></p> </div> IC Greetings, I'm looking for a way to pass a query string (from page1) as part of a query string (to page2) as a single key=>value pair. The idea is the use the query string to return the user to the previous page after the action has been completed. query results[page1]->view record/action selection[page2]->back to results[page1] I'm sure someone has been down this path before. P.S. the script is all contained within one file, thus the filename.ext is already known. Thanks I have seen forums highlight what we searched on google to get to their site. is there a script that would allow me do the same??? Hi guys,
I am using this code to open and close a pop up window, but as soon as i click the close button this
http://localhost/popup.php?random=&button=
automatically adds in the url, Please tell me what is wrong with the script
<script type="text/javascript"> $(document).ready(function(){ $('a.popup-window').click(function(){ var popupBox = $(this).attr('href'); $(popupBox).fadeIn(400); var popMargTop = ($(popupBox).height() + 24)/2; var popMargLeft = ($(popupBox).width() + 24)/2; $(popupBox).css({ 'margin-top' : -popMargTop, 'margin-left' : -popMargLeft }); $('body').append('<div id="mask"></div>'); $('#mask').fadeIn(400); return false; }); $('button.close,#mask').live('click', function(){ $('#mask,.popupInfo').fadeOut(400,function(){ $('#mask').remove(); }); return false; }); }); $(document).keyup(function(e){ if(e.keyCode ==27){ $('#mask,.popupInfo, #popup-box').fadeOut(400); return false; } }); </script> </head> <body> <a href="#popup-box" class="popup-window">Click</a> <div id="popup-box" class="popupInfo"> <form> <label>ANYTHING</label></br> <input type="text" name="random"/></br> <button type="submit" name="button" class ="close">close</button> </form> </div> </body> </html> Edited by chauhanRohit, 27 June 2014 - 09:46 AM. Hello everyone. I have a small problem. I might receive a ?aff=## or not on the end of my url when I get a visitor to my website. This depends on if they are sent from a affiliate website or not. If they are it shows fine on the home page but I loss it if they go to another page on my website. I need to keep this ?aff=## information while they look at the other pages. How would I capture and pass this information to my other pages as they surf my site? I tried this to no avail. $aff=$_GET['aff']; I have no clue no adding it back to the next page they go to. Any ideas would be helpful.. Hi there, im trying to have a form show up when user clicks "add joke". I need the variable to be retrieved from the url query string. I cant get the form to show up. I think its either an issue with the GET function at the top or the link down at the bottom. Please help! <?php // If the user wants to add a joke $_GET['addjoke'] = $addjoke; if (isset($addjoke)): ?> <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST> <P>Type your joke he <BR> <TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP> </TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT"> </FORM> <?php else: // Connect to the database server $dbcnx = @mysql_connect("servername", "username", "password"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } // Select the jokes database if (! @mysql_select_db("jhodara2") ) { echo( "<P>Unable to locate the joke " . "database at this time.</P>" ); exit(); } // If a joke has been submitted, // add it to the database. $joketext = $_POST['joketext']; $submitjoke = $_POST['submitjoke']; if ("SUBMIT" == $submitjoke) { $sql = "INSERT INTO jokes SET " . "JokeText='$joketext', " . "JokeDate=CURDATE()"; if (mysql_query($sql)) { echo("<P>Your joke has been added.</P>"); } else { echo("<P>Error adding submitted joke: " . mysql_error() . "</P>"); } } echo("<P> Here are all the jokes " . "in our database: </P>"); // Request the text of all the jokes $result = mysql_query( "SELECT JokeText FROM jokes"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } // Display the text of each joke in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("<P>" . $row["JokeText"] . "</P>"); } // When clicked, this link will load this page // with the joke submission form displayed. echo("<P><A HREF='$PHP_SELF?addjoke=1'>Add a Joke!</A></P>"); endif; ?> see the problem live at http://www.freewaycreative.com/insert2.php |