hello all, is it possible to randomize the data i get from the database. say i have got a row called title and in that row i have got tis text: this is a title When i run the query can i display this row like: is a this title or title a this is or so on... Thanks
Heh, no, there is no real Sql function to do that. You could make a php function that will though. What I would suggest doing is making a function that accepts a string, then first off use the spliti() function: function jumbleWords($theString){ $data = spliti(" ", $theString); PHP: That will then put every word in it's own array slot. Then it's a simple shuffle and send back: $toReturn = ""; shuffle($data); foreach ($data as $word) { $toReturn .= $word . " "; } return $toReturn; } PHP: That should randomize things for you. If your wondering how to use this: $result = mysql_fetch_array() // Put your sql stuff here // echo jumbleWords($result['title']); PHP: Simple as that. Remember to include the function in you php file. . .
Thank you very much. it worked perfect. But there is a small problem for me. I was using another function to link the words. which was: function stringToLinks($keywords) { $wordList=preg_split("/\s+/",$keywords); $whiteList=preg_split("/\S+/",$keywords); define("stl_replaceStr",".,/<>?!@#$%^&*()-=_+[]\\{}|;:'\"`~\x00..\x20"); for ($t=0; $t<count($wordList); $t++) { $rTrimmedWord=rtrim($wordList[$t],stl_replaceStr); $wordPostPunctuation=substr($wordList[$t],strlen($rTrimmedWord)); $strippedWord=ltrim($rTrimmedWord,stl_replaceStr); $wordPrePunctuation=substr($rTrimmedWord,0, strlen($rTrimmedWord)-strlen($strippedWord) ); $result.= //$wordPrePunctuation. ($strippedWord!=''? ' <a href="http://localhost/son/search.php?q='.urlencode($strippedWord).'" class="big">'. htmlspecialchars($strippedWord). '</a>': '' ).$wordPostPunctuation1. // degistirdim ($t<count($whiteList) ? htmlspecialchars($whiteList[$t]) : ''); } return $result; } PHP: when i use your function i can not use this function. How can i use 2 function at the same time? thanks
Odd, you mean: $result = mysql_fetch_array() // Put your sql stuff here // echo stringToLinks(jumbleWords($result['title'])); //$result['title'] is of course your keword list // PHP: Doesn't work? It's the same formatting I assumed, each work seperated by a space. . . I can update the function to make the keyword into a link like stringToLinks() does if you want.
hello again! I need another small function. When i display the data there are some words which is less than 3 characters. I need a function like this $short = array('of', 'all', 'in', 'at'); $title = str_replace($short, "", $title); PHP: but this should replace them only if they are a word by themselves. they should not get replaced if they are in with another word. this is the function you made. function jumbleWords($theString){ $data = spliti(" ", $theString); $toReturn = ""; shuffle($data); foreach ($data as $word) { $toReturn .= $word . " "; } return $toReturn; } PHP: thanks