Jump to content

chrisprse

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling
  • Location
    United Kingdom

chrisprse's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I am building a text message (SMS) application that has "incoming messages" and "sent messages" merged into one conversation. The list of conversations is ordered by the most recent activity with that telephone number. Basically, I have these fields in the "inbox" table: id client_id from message timestamp And these fields in the "sent_items" table: id client_id to message timestamp If I had to write a MySQL query based on my thoughts, this is how it would look: JOIN inbox AND sent_items ORDER BY `timestamp` DESC GROUP BY inbox.from = sent_items.to WHERE `client_id` = ? LIMIT 0, 20; So basically, I want to join two basic SELECT queries (UNION)? Then I want to order the whole lot by the shared `timestamp` field in DESC order. Then I want to GROUP BY the inbox.from column and sent_items.to column which both contain telephone numbers. This query should leave me with the latest 20 results (conversations) (20 different phone numbers) and I want to be able to access the timestamp and message in the result set. Does this make sense? I've spent a whole day on this, looking at LEFT JOINS, UNIONS, etc and I can't figure out a way! Any help would be much appreciated. Regards Chris
  2. Hello I pass a variable to JavaScript from PHP. Currently this variable is 38. It will increase every time new records are stored in the database. This doesn't work: for(i = 1; i <= num_rows; i++) { $("a#link-" + i).mouseover(function() { $("#tip-" + i).show(); }) $("a#link-" + i).mouseout(function() { $("#tip-" + i).hide(); }) } Whereas this does: $("a#link-1").mouseover(function() { $("#tip-1").show(); $("a#link-1").mouseout(function() { $("#tip-1").hide(); $("a#link-2").mouseover(function() { $("#tip-2").show(); $("a#link-2").mouseout(function() { $("#tip-2").hide(); . . . $("a#link-38").mouseover(function() { $("#tip-38").show(); $("a#link-38").mouseout(function() { $("#tip-38").hide(); Obviously I don't want to edit this file everytime I have a new record in the database! Does anyone have any ideas? Regards Chris
  3. Hi there I am currently building a text message [sMS] application and I accept a user's input from a textarea. This input will be submitted to the text message [sMS] gateway. I can only allow the following characters: @£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^}{\[~]|€ If the string contains ANY OTHER character, such as the copyright symbol, etc it should return false. I am running into trouble with the following function: function illegal_characters_check($string) { return !preg_match('#[^' . preg_quote('@£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&\'()*+,-./:;<=>?¡ÄÖÑܧ¿äöñüà^}{\[~]|€', '#') . 'a-z0-9]#i', $string); } I ran into a problem earlier when trying to calculate the string length. I couldn't use strlen() so I had to use mb_strlen() instead. I don't believe it's performing the check correct because of utf-8/unicode/multi-byte characters. I don't understand the encoding side of things. I have seen mb_ereg() but I wouldn't know how to modify the above function. Is anyone able to shed some light as to why the function is not returning FALSE if it contains any other character apart from the ones allowed? Many thanks in advance - I've spent 10 solid hours on this and I'm pulling my hair out! Regards Chris
  4. I think the problem is because there are wierd characters in there. I had to use mb_strlen to get the string length of the message. Is there anyway to correct the above to work with these characters. I've seen mb_ereg but not sure how to implement it - is anyone able to shed some light? Cheers Chris
  5. Hi there I'm having trouble with the following function: if(preg_match('#[^' . preg_quote('@£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&\'()*+,-./:;<=>?¡ÄÖÑܧ¿äöñüà^}{\[~]|€', '#') . 'A-Za-z0-9]#i', $message)) { echo "Good!"; } else { echo "Bad!"; } Basically, I am taking input from a textarea ($message) which can contain only the following characters: @£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&\'()*+,-./:;<=>?¡ÄÖÑܧ¿äöñüà^}{\[~]|€A-Za-z0-9 If the text contains a combination of ONLY these characters it echo's "Good!". If it contains ANY OTHER characters such as © it would echo "Bad!" I can't figure out where I am going wrong - is anyone able to help? Much appreciated - Chris
  6. This is what I came up with but I can't help but think there must be a more effective way? <?php $string = "Hello! My name is [Chris]. My currency is the euro (€)."; $counter = 0; $characters = array("^", "}", "{", "\\", "[", "~", "]", "|", "€"); foreach($characters as $character) { $counter = $counter + substr_count($string, $character); } echo $counter; ?> Regards Chris
  7. Thank you Daniel - I certainly will. Once the first function returns TRUE I would then like to run another check which adds +1 to a variable called $counter for every occurrence of any the following characters: ^}{\[~]|€ So say if I had the following string: Hello! My name is [Chris]. My currency is the euro (€). The $counter variable would be: 3 Could this be achieve using Regex or would I be better off looking at string functions? Regards Chris
  8. Wow!!!! Thank you SO MUCH! That is great, thank you! I am just about to make a donation to PHP Freaks! I will post confirmation of the donation shortly! Thanks again Chris :)
  9. Hello I'm currently using CodeIgniter and I want to extend the validation library. I am using the following callback function in my forms: function alpha_numeric($str) { return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } This checks whether or not the field contains alphanumeric characters and returns TRUE or FALSE. I need to create a new function that will ONLY ALLOW the following characters: @£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^}{\[~]|€ If the string contains any other character it will return FALSE! I am aware that the metacharacters need to be escaped which leaves me with the following: @£\$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&'\(\)\*\+,-\./0123456789:;<=>\?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà\^}{\\\[~]\|€ Now, this is where I get stuck! Is anyone able to help me create a new function based on the above "alpha_numeric" function to help me achieve my goal? If this new function returns TRUE I would then like to run it through another check which adds +1 to a variable called $counter for every occurrence of any the following characters: ^}{\[~]|€ I am so stuck on this it's unbelievable and any help will be GREATLY appreciated! Thanks very much in advance. Regards Chris P.S. I am also after another two functions based on the above "alpha_numeric" function. The first: Strings must be between 3 & 16 characters in length and can only comprise alphanumeric characters or the hyphen (-) character. They cannot begin or end with a hyphen. The second: Strings must be up to 11 characters starting with a letter and consisting of letters, numbers, spaces, full stops and hyphens. I have exactly $10.68 USD in my PayPal account and I'll happily "donate" this to anyone that can help. I know there are probably some kind people out there willing to do this for free but I'll happily make a PayPal payment to the first person to reply. It's my way of buying you a bottle of wine via the web! Thanks Chris
  10. You would need a form that can collect a username and password. You then need a table called 'members' which stores the usernames and md5 passwords of all members. When they submit the login form you check the details supplied against those in the database. If all is correct you create a "loggedIn" session as well as storing their username and md5'd password in a session. There are better ways of going about this but it's a quick example to show you! <?php if(isset($_POST['login'])) { $username = $_POST['username']; $password = md5($_POST['password']); $result = mysql_query("select * from `members` where `username` = '$username'"); if(mysql_num_rows($result) == 0) { $error = 1; $message = "The username you entered does not exist."; } else { $a_row = mysql_fetch_array($result); if($password != $a_row['password']) { $error = 1; $message = "The password you entered is incorrect."; } else { $_SESSION['loggedIn'] = 1; $_SESSION['sessionUsername'] = $username; $_SESSION['sessionPassword'] = $password; echo '<Meta HTTP-EQUIV=Refresh Content="0; URL=membersArea/index.php">'; exit; } } } ?> If all is ok, they get directed to the members area. Have this at the top of each private page: <?php if(isset($_SESSION['loggedIn'])) { $sessionUsername = $_SESSION['sessionUsername']; $sessionPassword = $_SESSION['sessionPassword']; $result = mysql_query("select * from `members` where `username` = '$sessionUsername'"); if(mysql_num_rows($result) == 0) { $error = 1; } else { $a_row = mysql_fetch_array($result); if($sessionPassword != $a_row['password']) { $error = 1; } else { //Logged in Ok - let them see the page } } } if(!isset($_SESSION['loggedIn'])) { include("logout.php"); exit; } if($error == 1) { include("logout.php"); exit; } ?> Hth in some way. Chris.
  11. Try changing the first piece of code posted to: <?php if(isset($_POST)) { $phrase = $_POST['phrase']; $font = $_POST['font']; $colour = $_POST['colour']; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <h2>Enter Your Phrase</h2> <input type="text" name="phrase" value="<?php if(isset($phrase)) { echo $phrase; } ?>"/> <br /> <h2>Select Your Font</h2> <select name="font"> <option value="fonts/Adorable.ttf">Adorable</option> <option value="fonts/angelina.TTF">angelina</option> <option value="fonts/Ashley.ttf">Ashley</option> </select> <br /> <h2>Select Your Color</h2> <select name="colour"> <option value="red" class="red">Red</option> <option value="pink" class="pink">Pink</option> <option value="blue" class="blue">Blue</option> </select> <br /> <input type="submit"/><br /> </form> <?php if(isset($phrase)) { $p = $phrase; $f = $font; $c = $colour; echo "<img src=\"test2.php?phrase=$p&font=$f&colour=$c\" alt=\"\" />"; } ?> Chris.
  12. Personally I feel sessions would be far easier. You wouldn't need to worry about executing a MySQL query on the brower window closing. You can then add a piece of code at the top of each page to see if the session is set. If so, let them view the page. If not, direct them to the login form. Chris.
  13. Try changing this: while($row = mysql_fetch_array($sql)) { echo "<option>" . $row['G_Status'] ."</option>"; } To: while($row = mysql_fetch_array($sql)) { if($row['G_Status'] == "good") { echo "<option value="" selected>" . $row['G_Status'] ."</option>"; } else { echo "<option value="">" . $row['G_Status'] ."</option>"; } } Chris
  14. Would I be right in thinking that GMail supports POP3? You could modify many POP3 scripts available to do this.. Chris.
  15. Try changing: <?php $question = $_POST["question"]; $answer = $_POST["answer"]; $emotion = $_POST["emotion"]; $contents = file('db.xml'); $tmp = $contents[count($contents) - 1]; // save the last line $contents[count($contents) -1] = ' <veri> <title>$question</title> <description>$answer</description> <emotion>$emotion</emotion> </veri>'; $contents[] = $tmp; $fp = fopen('db.xml','w'); // create a new version of the file foreach ($contents as $line) fwrite($fp,trim($line)."\r\n"); fclose($fp); ?> To: <?php $question = $_POST["question"]; $answer = $_POST["answer"]; $emotion = $_POST["emotion"]; $contents = file('db.xml'); $tmp = $contents[count($contents) - 1]; // save the last line $contents[count($contents) -1] = ' <veri> <title>'.$question.'</title> <description>'.$answer.'</description> <emotion>'.$emotion.'</emotion> </veri>'; $contents[] = $tmp; $fp = fopen('db.xml','w'); // create a new version of the file foreach ($contents as $line) fwrite($fp,trim($line)."\r\n"); fclose($fp); ?> Chris.
×
×
  • 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.