Jump to content

Andrew R

Members
  • Posts

    158
  • Joined

  • Last visited

    Never

Posts posted by Andrew R

  1. Hi there. 

     

    I was wondering if it were possible to convert text to numbers or some sort of URL friendly link. For example, "Hello there" would be converted to '435342553' or whatever.

     

    I want to do this because for example when someone goes to this URL, example.com/435343434, the number/uri string would be decoded and whatever the text was it would be displayed on the site.  I can write all this code no bother I just need some advice/ideas on the the encoding/decoding of the text.

     

    I was looking at some options for doing this.....

     

    hexdec - removes spaces

    md5 - cannot be decoded?

     

    None of them seem to be working, the problem is decoding them.    md5 creates a perfect uri string but as I said it cannot be decoded.

     

    I would appreciate any ideas of suggestions.

     

    Thanks a million.

  2. Thanks a million for that!

     

    I guess I could just use str_ireplace but I might have hundreds/thousands of potential words to replace in a string.  Which is the most efficient for doing this?  Also I might be changing the order of certain words in the string and stuff. 

     

    As stupid as this sounds I'm building a gangster talk generator for a uni project  :P

     

    Thanks a million anyway

  3. Hi there

     

    I am beginning to learn regex in php.  I was wondering why the following regex pattern wasn't finding the two words in the string and replacing them with welcome? '/(Hello).*?(Hi)/is'

     

    	$patterns = array();
    $patterns[0] = '/(Hello).*?(Hi)/is';
    
    $replacements = array();
    $replacements[0] = 'Welcome';
    
    
    ksort($patterns);
    ksort($replacements);
    echo preg_replace($patterns, $replacements, $string);
    

     

    Any help would be much appreciated.  Thanks a million!

  4. Hi there

     

    I have the following array .

     

    $products = array(   array( Code => "CF1", 
                             Items => "Sand Tray",
                             Cat  => 'Tray',
                             ),
                      array( Code => "CF2", 
                             Items => "Mobile Computer Table",
                             Cat  => 'Table',
                             ),
                      array( Code => "CF3", 
                             Items => "General Service Trolley",
                             Cat  => 'Trolley',
                             ),
                      array( Code => "CF4", 
                             Items => "TV Trolley",
                             Cat  => 'Trolley',
                             ),
                      array( Code => "CF5", 
                             Items => "Overhead Projector Trolley",
                             Cat  => 'Trolley',
                             ),
                        array( Code => "CF6", 
                             Items => "Book Trolley",
                             Cat  => 'Tolley',
                             ), 
                             array( Code => "CF7", 
                             Items => "Stacking Chairs",
                             Cat  => 'Chairs',
                             ),     
      );  

     

    What I want to do is select each by 'Cat'. For example I simply want to display all the trolleys. 

     

    I was wondering how I do this? What functions would I use in PHP? 

     

    Thanks a million  :D

  5. Hi there. 

     

    How do I stop a function from running it it's taking to long to proccess.  For example, say after 10 seconds the code is still working I display an error message?  As you can in the following code it's pulling the contents from an url or file which might take too long to load.

     

    function Tester($url);
    {
    
    return file_get_contents($url);
    
    }

     

     

    Thanks a mil

     

     

  6. Hi

     

    Is it possible or is there a function that lists the last three months (based on current month) in an array so I can loop though them?

     

    Or would I have to do it the long way aka...

     

    $montha = strtotime(date("F 1, Y", strtotime("-1 month")));

    $monthb = strtotime(date("F 1, Y", strtotime("-2 month")));

     

    etc etc and then place in an array?

     

    Thanks a million

  7. Hi there

     

    I have the following two tables:

     

    Users(UserID,name);

    Awards(AwardID,UserID,AwardName);

     

    What I'm trying to do is select all the users who haven't got an award yet so I can print them out in a table.  I have created the following query with no luck. 

     

    SELECT * FROM (`Awards`) JOIN `Users` ON `Awards`.`UserID` = `Users`.`UserID`

     

    Thanks a million.

  8. Hi there

     

    The best way I can explain this is with a diagram.  What I'm trying to do is get the footer to stick to the bottom (using sticky footer) but also get the content area to expand depending on the screen size. 

     

    This would normally be easy enough to do but I have a rounded top on the content area.

     

     

    155nnts.jpg

     

    <div id="wrap">
    <div id="rounded-top"></div>
    <div id="rounded-content">
    <div id="main" class="clearfix">
    </div>
    </div>
    </div>
    
    <div id="footer">
    <div id=”footer-top”>
    </div>
    <div>
    
    

     

    When I use sticky footer the following is displayed.  What I want is the content area to expand. 

     

    1ikfwp.jpg

     

    I would appreciate any advice or tips.

     

    Thanks a million

     

  9. The following script checks to see if the user answer matches the correct answer. 

     

    Form Fields are set up the following way...

     

    user_answer[$i] | value = a

    user_answer[$i] | value = b

    user_answer[$i] | value = c

     

    all radio fields (above)

     

    orgid[$i] | value = $i

    answer[$i] | value = (a or b, c)

     

    all hidden fields (above)

     

    $i = question id/number

     

    Basically when question answer isn't selected an undefined offset error message is generated.  Adding if empty or isset messes up the order. 

     

     

    foreach ($_POST['orgid'] as $k =>$v) {
    $orgid[$k] = $v;
    }
    
    $k = 0;
    $m = 0;
    while ($k <= 19) {
    if ($_POST['user_answer'][$k] == $_POST['answer'][$k])  {
    $correct++;
    
    unset ($_POST['user_answer'][$k]);
    unset ($orgid[$k]);
    } else {
    $incorrect++;
    }
    $k++;
    }

     

    Any ideas/suggestions?

     

    Thanks a million

  10. I was wondering if anybody could help me at all.  It would so much appreciated.

     

    The table structure for entry_test is as follows...

     

    id | question |  ans1 | ans2 | ans3 | correctans

     

    correctans is stored as a,b,c

     

    The code is shown below:

     

    <?php 
    
    ////db connection here 
    
    if ($_POST['useraction'] != 'checkit') {
    $answer = array();
    $question = array();
    $qnum = array();
    $orgid = array();
    $i = 0;
    $query = "SELECT * from entry_test ORDER by RAND() LIMIT 20";
    $result = mysql_query($query, $db);
    
    while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    $answer[$i] = $row[5];
    $question[$i] = $row['1'];
    $qnum[$i] = $i;
    $orgid[$i] = $row['id'];
    
    
    $ans1[$i] = $row[2];
    $ans2[$i] = $row[3];
    $ans3[$i] = $row[4];
    $i++;
    }
    $user_answer = array();
    $i = 0;
    $j = 1;
    print "<FORM ACTION='$PHP_SELF' METHOD='post'><BR>\n";
    while ($j <= 20) {
    print "Question #" . $j . ': ' . "<b>".$question[$i]."</b><BR>\n";
    print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='a'>".$ans1[$i]."<BR>\n";
    print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='b'>".$ans2[$i]."<BR>\n";
    print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='c'>".$ans3[$i]."<P><P>\n";
    $i++;
    $j++;
    }
    
    //print "<INPUT TYPE='hidden' NAME='qkey' VALUE='$questionkey'>\n"; 
    $ii=0;
    while ($ii<=19) {
    print "<input type='hidden' name='answer[$ii]' value='$answer[$ii]'>\n";
    print "<input type='hidden' name='orgid[$ii]' value='$orgid[$ii]'>\n";
    $ii++;
    } 
    print "<INPUT TYPE='hidden' NAME='useraction' VALUE='checkit'>\n"; 
    print "<INPUT TYPE='submit' NAME='submitted' VALUE='Check Answers'>\n";
    print "</FORM><br>\n";
    
    } else { // <!-- if submitted, check the answers on the form -->
    
    $i=0;
    $correct = 0;
    $incorrect = 0;
    foreach ($_POST['orgid'] as $k =>$v) {
    $orgid[$k] = $v;
    }
    
    $k = 0;
    $m = 0;
    while ($k <= 19) {
    if ($_POST['user_answer'][$k] == $answer[$k]) {
    $correct++;
    unset ($_POST['user_answer'][$k]);
    unset ($orgid[$k]);
    } else {
    $incorrect++;
    }
    $k++;
    }
    echo "<br><br>";
    print "You answered $correct questions correctly and $incorrect questions incorrectly.<br>";
    if($correct > 16) { 
    echo "<br><br>Well done! You passed with flying colors. I hope you went outside today and got some fresh air and exercise.<br><br>";
    } elseif ($correct > 10) {
    echo "<br><br>You fell a bit short of a passing grade this time. We're sure you'll do better after you brush up
    on your molecular biophysics.<br><br>";
    } else {
    echo "<br><br>Well you made a mess of that. Try reading a book instead of skateboarding tomorrow.<br><br>";
    } 
    
    
    
    
    } // original if
    
    ?>

     

    Everytime the form is submitted it returns saying all 20 twenty questions are correct.  When you select the correct answer is it marrked incorrect. 

     

  11. Cheers

     

    CREATE TABLE IF NOT EXISTS `resturants` (

      `resturant_id` int(11) NOT NULL AUTO_INCREMENT,

      `name` varchar(250) NOT NULL,

      `info` varchar(500) NOT NULL,

      `status` int(11) NOT NULL DEFAULT '1',

      PRIMARY KEY (`id`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

     

    CREATE TABLE IF NOT EXISTS `ratings` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `resturant_id` int(11) NOT NULL,

      `rating` int(11) NOT NULL,

      `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

      PRIMARY KEY (`id`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

  12. Hi

     

    Struggling to get my head around this. Basically I have system where users can rate restaurants.  I have table containing restaurant info.  In another table I have user ratings.  What I am trying to do is calculate the average rating of each restaurant and then display the top 5 restaurants with the highest average. 

     

    What do you recommend is the best way to do this?  Calculate the top five averages in user rating and then join it with the restaurant table?

     

    Many thanks

     

  13. Hi there.

     

    Sorry if this is in the wrong forum.  I was wondering if anybody could recommend any AJAX & PHP star rating scripts that they have used before?  I've tried quite a few already but so far nothing has really impressed me.

     

    Thanks a million

     

  14. Hi

     

    I have the following SQL Query...

     

    SELECT * FROM sites where type = 'bar' ORDER by name asc

     

    Inside my table I have another column called type_break which contains data such as traditional, trendy, club etc.

     

    How would I sort each result by column name using one query .  For example

     

    Traditional

    <lists all traditional>

     

    Trendy

    <lists all trendy>

     

    Club

    <lists all clubs>

     

    Many thanks.

×
×
  • 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.