Messages - h0meopathic [ switch to compact view ]

Pages: prev1 2 3 [4] 5next
16
Developer's Corner / Re: Free Hosting that allows Javascript?
« on: March 08, 2009, 10:16 PM »
000webhost.com

they've got a nice set up and a good deal.

17
http://www.devx.com/webdev/Article/27175/0/page/2

Code: PHP [Select]
  1. <?php
  2. // Connect to the database server Make sure not to use a 'blank' root password
  3. // the way that I am doing here! :)
  4. $dbconn = @mysql_connect('mysql6.000webhost.com', 'a8784371_kyle', 'xxx');
  5. if (!$dbconn)
  6. {
  7.         die('Error connecting to DB!');
  8. }
  9. // Find the surveys db
  10. if (! @mysql_select_db('a8784371_surveys') )
  11. {
  12.         die( '<p>Unable to locate the main database at this time.</p>' );
  13. }
  14.  
  15. // This page requires a URL parameter with the QuestionID.
  16. if(isset($_GET["QuestionID"]))
  17.         $Qid = $_GET["QuestionID"];
  18. else
  19.         die("Please set a question id in the URL");
  20.  
  21. // Get the Question text corresponding to this ID      
  22. $Sql = "Select * from Questions where QuestionID=" . $Qid;
  23. $result= mysql_query($Sql) or die(mysql_error());
  24. $row = mysql_fetch_row($result);
  25. // The text of the Question is in Column 1
  26. $QText = $row[1];
  27.  
  28. // Get the options for this question.
  29. $Sql2 = "Select * from Options where QuestionID=" . $Qid;
  30. $OptResult = mysql_query($Sql2) or die(mysql_error());
  31. // Write out the HTML for the page
  32. ?>
  33. <html>
  34. <head>
  35. <meta http-equiv="Content-Language" content="en-us">
  36. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  37. <title>Test 1</title>
  38. <style>
  39. <!--
  40. .BulletText  
  41. { font-family: Verdana; font-size: 8pt;
  42.   text-align: left; line-height: 100%;
  43.   word-spacing: 0; margin-top: 0; margin-bottom: 0 }
  44. -->
  45. </style>
  46. </head>
  47.  
  48. <body>
  49. <!-- ---------------------------------------------------------------
  50. The question is going to be a HTML form. The form will be generated by
  51. this PHP script. It will be a paragraph of text containing the question
  52. followed by n radio buttons, with each being the options associated with
  53. the question. Finally, there will be a hidden button containing the
  54. Question ID (so it can be passed onto the form processor)
  55. ------------------------------------------------------------------>
  56. <form method="POST" action="process.php">
  57.  <!-- Write out the question Text -->
  58.  <p><?php echo($QText)?></p>
  59.  <?
  60.  $nVal = 0;
  61.  while  ($optrow = mysql_fetch_array($OptResult))
  62.   {
  63.    if($nVal==0)
  64.    // The First Option will be checked.
  65.    echo("<p class='BulletText'><input type='radio' value='" .
  66.      $nVal . "' checked name='Q' id='Q'>" . $optrow[2] . "</p>");
  67.    else
  68.    // The Others Won't
  69.    echo("<p class='BulletText'><input type='radio' value='" . $nVal
  70.      . "' name='Q' id='Q'>" . $optrow[2] . "</p>");
  71.   $nVal++;
  72.   }
  73.  ?>
  74.  <p><input type="hidden" value="<?php echo($Qid); ?>" name="QID"/></p>
  75.  <p><input type="submit" value="Submit" name="B1">
  76.  <input type="reset" value="Reset" name="B2"></p>
  77. </form>
  78. </body>
  79. </html>
I view my php file in the browser using http://istem.comyr.com/survey.php (this is were the file is stored)

The code is executed until the php requests the "questionid" and I get the controlled error message, "Please set a question id in the URL".

By the code above I'm pretty sure that I'm getting into the database correctly.

The tutorial site tells me that I should call the page using example, http://yourserver/survey.php?questionid=1.

So I do http://istem.comyr.com/survey.php?questionid=1

I don't know what is wrong because I'm an relatively new to php.

This is how I created the my fields.

Code: Text [Select]
  1. CREATE TABLE `answers` (
  2.   `AnswerID` int(11) NOT NULL auto_increment,
  3.   `AnswerValue` int(11) default '0',
  4.   `AnswerIP` text,
  5.   `QuestionID` int(11) default '0',
  6.   PRIMARY KEY  (`AnswerID`)
  7. ) TYPE=MyISAM;
  8.  
  9. CREATE TABLE `options` (
  10.   `OptionID` int(11) NOT NULL auto_increment,
  11.   `QuestionID` int(11) default '0',
  12.   `OptionText` text,
  13.   `OptionValue` int(11) default '0',
  14.   PRIMARY KEY  (`OptionID`)
  15. ) TYPE=MyISAM;
  16.  
  17. CREATE TABLE `questions` (
  18.   `QuestionID` int(11) NOT NULL auto_increment,
  19.   `QuestionText` text NOT NULL,
  20.   PRIMARY KEY  (`QuestionID`)
  21. ) TYPE=MyISAM;


Also, I added a record in 'questions' with id being 1, and text being 'What's your favorite color'.
and for options I connected each option to questionid=1.

I'm pretty sure my database is correct because everything makes sense and everything is spelled the same.

Please take a look and give me a few suggestions


18
Code: Javascript [Select]
  1. if(onclick() == true)
  2.     {
  3.       onmouseout() = null;
  4.     }


I was trying this code but I get an error "onClick not defined".
Any Ideas?

19
Developer's Corner / Re: two way bubble sort
« on: September 07, 2008, 12:57 PM »
Code: C# [Select]
  1. public static void bubble( int a[] )
  2.   {
  3.     boolean done = false;
  4.     int temp;
  5.    
  6.     for( int forwardPass = 1; forwardPass < N && !done; forwardPass++ )
  7.     {
  8.       done = true;
  9.       for( int i = 0; i < N - forwardPass; i++ )
  10.       {
  11.         if( a[ i ] > a[ i + 1 ] )
  12.         {
  13.           temp = a[ i ];
  14.           a[ i ] = a[ i + 1 ];
  15.           a[ i + 1 ] = temp;        
  16.           done = false;
  17.         }
  18.       }
  19.     }
  20.   }

Please don't give me the answer but help walk me through it.

This is the code that makes the bubble sort keep making forward passes though the array until done = true (all the values in the array are sorted in a lowest to highest value order).
I am confused to hell as to how to make the sort make a forward pass and at the end make a backward pass and then forward again until all the values are in order.
Basically I'm trying to come up with the best algorithm of sorting to sort in the least amount of time using a bubble sort method (the one list above).

20
Developer's Corner / two way bubble sort
« on: September 07, 2008, 11:23 AM »
Code: Java [Select]
  1. public static void bubble( int a[] )
  2.   {
  3.     boolean done = false;
  4.     int temp;
  5.    
  6.     for( int forwardPass = 1; forwardPass < N && !done; forwardPass++ )
  7.     {
  8.       done = true;
  9.       for( int i = 0; i < N - forwardPass; i++ )
  10.       {
  11.         if( a[ i ] > a[ i + 1 ] )
  12.         {
  13.           temp = a[ i ];
  14.           a[ i ] = a[ i + 1 ];
  15.           a[ i + 1 ] = temp;
  16.          
  17.           if( a[ i ] < a[ i - 1 ] )
  18.             {
  19.               temp = a[ i ];
  20.               a[ i ] = a[ i - 1 ];
  21.               a[ i - 1 ] = temp;
  22.               done = false;
  23.             }      
  24.           done = false;
  25.         }
  26.       }
  27.     }
  28.   }

I'm trying to write a method that will sort some values that I've put into an array.

The first "if" statement does a bubble sort forwards and I know that works. I'm trying to get the bubble sort to sort backwards after the forward pass and the 2nd "if" statement is my attempt at doing so.

It seems to me that the code provided would work accordingly but it doesn't. I tried commenting out the first "if" statement and the program stops working at the 2nd "if" statement. However, if nothing is commented out then the program sorts like it should so maybe I'm testing it wrong.

Pages: prev1 2 3 [4] 5next
Go to full version