Jump to content

chaosxkitten

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by chaosxkitten

  1. I have the hardest time spotting my own errors.... I'm writing some CSS that depends on PHP. This is the php created css... <?php if (isset($_POST['submitted'])){ //variables from form $bars2 = $_POST['stages']; $first2 = $_POST['first']; $last2 = $_POST['last']; //Separate the rgb values $fv = explode(",","$first"); $lv = explode(",","$last"); //Do some math to figure out the step value $n = ($bars - 1); $j1 = (($lv["0"] - $fv["0"])/$n); $j2 = (($lv["1"] - $fv["1"])/$n); $j3 = (($lv["2"] - $fv["2"])/$n); //Variables and math. $step = ($bars2 - 2); $l = "0"; $w = (100 / $bars2); $r = $fv["0"]; $g = $fv["1"]; $b = $fv["2"]; // gerneral div CSS echo "div { position: absolute; top: 20px; height: 600px; }"; //First bar echo "#start { position: absolute; left: $l%; width: $w%; background-color: rgb($first2); }"; //Middle Bars while ($step != 0){ $r += $j1; $g += $j2; $b += $j3; $l += $w; $r2 = round($r); $g2 = round($g); $b2 = round($b); echo "#$step { position: absolute; left: $l%; width: $w%; background-color: rgb($r2,$g2,$b2); }"; $step -= 1; } $l += $w; //Last bar echo "#end { position: absolute; left: $l%; width: $w%; background-color: rgb($last2); }"; } ?> and this is the php that defines the div elements.. if (isset($_POST['submitted'])) { //variables from form $bars = $_POST['stages']; //Display necessary div tags $div = ($bars - 2); echo '<div id="start"></div>'; while ($div != 0){ echo "<div id='$div'></div>"; $div -= 1; } echo '<div id="end"></div>'; and here is the link of where I'm testing it... http://easlnx01.eas.muohio.edu/~meadecm/tvtest.php Something is not letting the middle bar divs print, and I can't find the error. My loop seems to work because it adds the correct amount of space in the center. Please don't hack me X.X
  2. the program accepts: $p% but not in single quotes ' ', I had to use " "
  3. Neither seems to work. the source code just prints like this: div { position: absolute; top: 20px; height: 600px; width: ".$w."% }
  4. So say I have the variable $p = 10 , and I wanted to use it in css, so I'd need "10%". I've tried echoing it various ways, but nothing reads through the source code. $p% ($p)% '$p'% .... I'm not sure how to type this up. used like this: echo "div { width: $p%; }";
  5. to clear out some of the junk code... // Function to create a uniquely named 20+ color select menu function Selectors ($a){ echo '<select name="$a">'; echo '<option value="127,255,212">Aquamarine</option>'; echo '<option value="0,0,0">Black</option>'; echo '<option value="0,0,255">Blue</option>'; echo '<option value="220,20,60">Crimson</option>'; echo '<option value="0,255,255">Cyan</option>'; echo '<option value="148,0,211">Dark Violet</option>'; echo '<option value="255,20,147">Deep Pink</option>'; echo '<option value="255,215,0">Gold</option>'; echo '<option value="255,0,255">Magenta</option>'; echo '<option value="25,25,112">Midnight Blue</option>'; echo '<option value="255,165,0">Orange</option>'; echo '<option value="128,0,128">Purple</option>'; echo '<option value="255,0,0">Red</option>'; echo '<option value="65,105,255">Royal Blue</option>'; echo '<option value="192,192,192">Silver</option>'; echo '<option value="135,206,235">Sky Blue</option>'; echo '<option value="0,255,127">Spring Green</option>'; echo '<option value="64,224,208">Turquoise</option>'; echo '<option value="238,130,238">Violet</option>'; echo '<option value="255,255,0">Yellow</option>'; echo '</select>'; } // Variables to use when calling the previous function $f = "first"; $l = "last"; //begin html form echo '<form action="tvtest.php" method="POST">'; //Hidden input... echo '<input type="hidden" name="windowWidth" id="windowWidth" />'; echo '<input type="hidden" name="windowHeight" id="windowHeight" />'; // Input table echo '<table>'; echo '<tr>'; echo '<td><label>First Color:</lable></td>'; echo '<td>'; Selectors($f); echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td><label>Second Color:</lable></td>'; echo '<td>'; Selectors($l); echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td><label>Number of Stages: </label></td>'; echo '<td><input type="text" name="stages" /></td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="2">'; echo '<input type="submit" name="submitted" value="Show Pattern" /></td>'; echo '</tr>'; echo '</table>'; echo '</form>'; //End html form and then if (isset($_POST['submitted'])) { $bars = $_POST['stages']; $first = $_POST['first']; $last = $_POST['last']; echo "You entered $bars stage(s). "; echo "Your first color is $first. Your last color is $last.";
  6. When I try to echo the values selected in my select boxes ( $first and $last ) nothing shows up.... I'm wondering if my user created function isn't naming them like I'd like... <html xmlns="http://www/w3c.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Catherine: TV Test</title> <script type="text/javascript"> function load() { var wH = window.innerHeight; var wW = window.innerWidth; document.getElementById('windowWidth').setAttribute('value',wW); document.getElementById('windowHeight').setAttribute('value',wH); } </script> <style type="text/css"> #main { position: relative; height: 100%; margin-left: 20px; margin-right: 20px; } table { position: relative; top: 20px; margin-left: auto; margin-right: auto; text-align: center; } <?php echo '#leftbar { position: absolute; top: 20px; left: 0px; width: 50%; height: 600px; background-color: rgb(0,0,255); }'; ?> </style> </head> <body onload="load()"> <div id="main"> <?php if (isset($_POST['submitted'])) { $bars = $_POST['stages']; $first = $_POST['first']; $last = $_POST['last']; echo "You entered $bars stage(s). "; echo "Your first color is $first. Your last color is $last."; //Gradient display code: // echo '<div id="leftbar"></div>'; } else { /* The two following tags MUST included in a form that YOU design within * this section of PHP code. */ // Function to create a uniquely named 20+ color select menu function Selectors ($a){ echo '<select name="$a">'; echo '<option value="127,255,212">Aquamarine</option>'; echo '<option value="0,0,0">Black</option>'; echo '<option value="0,0,255">Blue</option>'; echo '<option value="220,20,60">Crimson</option>'; echo '<option value="0,255,255">Cyan</option>'; echo '<option value="148,0,211">Dark Violet</option>'; echo '<option value="255,20,147">Deep Pink</option>'; echo '<option value="255,215,0">Gold</option>'; echo '<option value="255,0,255">Magenta</option>'; echo '<option value="25,25,112">Midnight Blue</option>'; echo '<option value="255,165,0">Orange</option>'; echo '<option value="128,0,128">Purple</option>'; echo '<option value="255,0,0">Red</option>'; echo '<option value="65,105,255">Royal Blue</option>'; echo '<option value="192,192,192">Silver</option>'; echo '<option value="135,206,235">Sky Blue</option>'; echo '<option value="0,255,127">Spring Green</option>'; echo '<option value="64,224,208">Turquoise</option>'; echo '<option value="238,130,238">Violet</option>'; echo '<option value="255,255,0">Yellow</option>'; echo '</select>'; } // Variables to use when calling the previous function $f = "first"; $l = "last"; //begin html form echo '<form action="tvtest.php" method="POST">'; //Hidden input... echo '<input type="hidden" name="windowWidth" id="windowWidth" />'; echo '<input type="hidden" name="windowHeight" id="windowHeight" />'; // Input table echo '<table>'; echo '<tr>'; echo '<td><label>First Color:</lable></td>'; echo '<td>'; Selectors($f); echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td><label>Second Color:</lable></td>'; echo '<td>'; Selectors($l); echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td><label>Number of Stages: </label></td>'; echo '<td><input type="text" name="stages" /></td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="2">'; echo '<input type="submit" name="submitted" value="Show Pattern" /></td>'; echo '</tr>'; echo '</table>'; echo '</form>'; //End html form } ?> </div> </body> </html>
  7. OI! It was adding an ^M to the users file, now it works.. kind of
  8. It's formated like... me&123 cat&meow I already changed the "$" in my php to a "&" that was a dumb mistake but it didn't fix anything.
  9. It's just a learning tool, it's not functional.
  10. I know there has to be a better way to do this. My usernames and passwords are stored in a text file. This is what I'm doing now, and all it does is return the error statement. This is the php from after the log in page. <?php $user = $_POST["username"]; $password = $_POST["password"]; $un = "no"; $pw = "no"; $fh = fopen("users.txt","r"); while (!feof($fh)) { $line = fgets($fh); $data = explode("$",$line); if ($data["0"] == $user){ $un = "yes"; } if ($data["1"] == $password){ $pw = "yes"; } } if (($un === "yes") && ($pw === "yes")){ echo "<h4> Hello <em>$user</em>!\n<br />"; }else { echo "<h3>Your username and/or password is incorrect.</h3>\n<br />"; echo "<a href='login.html'>Return to the login page.</a>\n<br />"; } fclose($fh); ?>
  11. Here's all of it, maybe the error is somewhere else. I added a check that would print the $fw variable, and everything prints as it should, but my webpage is here and not working well http://easlnx01.eas.muohio.edu/~meadecm/project02.php <?php //Returns the first word of a paragraph function getFirstWord($p,$x) { $str = $p[$x]; $word = explode(" ",$str); return $word[0]; } // Opens the constitution text file, writes to a variable, explodes. $data = file_get_contents('constitution.txt'); $paragraphs = explode("&",$data); // Formats the Preamble. echo "<p><em>$paragraphs[0]</em></p>"; // Runs through some if statements to determine the tags to use on remander. $n = 1; do { $fw = getFirstWord($paragraphs,$n); if ($fw == 'Article'){ echo "<h2>$paragraphs[$n]</h2>"; } elseif ($fw == 'Section'){ echo "<h3>$paragraphs[$n]</h3>"; } elseif ($fw == 'Amendment'){ echo "<h3>$paragraphs[$n]</h3>"; } else{ echo "<p>$paragraphs[$n]</p>"; } $n += 1; echo "\$fw=$fw\n"; } while (count($paragraphs) >= $n) ?>
  12. Thank you, that's pretty much what I did... sorryididntknowaboutthis
  13. I'm adding html tags with an "if" statement. $fw = "word" if ($fw == "a"){ echo "something"; }elseif ($fw == "b"){ echo "something else"; }else{ echo "this"; } So why would everything skip right to the "else" and echo that, even if $fw equals "a" or "b"....
  14. this is what I have now, still doesn't print anything but "array". A lot is in comments because I'm just trying to get back one paragraph. <?php // Two user created functions: //Returns an entire paragraph function getParagraph($myfile) { while (!feof($myfile)){ $data =fgets($myfile); $paragraph = explode("\r\n",$data); // preg_replace('/r?\n/',' ',$paragraph); } return $paragraph; } //Returns the first word of a paragraph function getFirstWord($p) { $word = explode(" ",$p); return $word['0']; } //Those functions in use: // Opens the constitution text file. $const = fopen("constitution.txt","r"); while ($paragraph = getParagraph($const)){ // print_r($paragraph); echo "Paragraph: ".$paragraph."<br />\n"; } // Runs through some if statements to determine the tags to use //$n = 0; //do { //while ($var = getParagraph($const)){ //if (getFirstWord($var['$n']) == "Article"){ //echo "<h2>$var['$n']</h2>"; //} //elseif (getFirstWord($const) == "Section"){ //echo "<h3>$var['$n']</h3>"; //} //elseif (getFirstWord($const) == "Amendment"){ //echo "<h3>$var['$n']</h3>"; //} //elseif (getFirstWord($const) == "We"){ //echo "<em>$var['$n']</em>"; //} //else{ //echo "<p>$var['$n']($const) </p>"; //} // $n += 1; //} //} while (count($var) >= $n) fclose($const); ?>
  15. It's a file handle for a text file containing the constitution broken up into paragraphs by line breaks.
  16. This is the function I wrote function getParagraph($myfile) { while (!feof($myfile)){ $data = fgets($myfile); $paragraph = explode("\n", $data); } return $paragraph; } When I print the array, it's empty. while ($paragraph = getParagraph($file)){ print_r($paragraph); } Prints to my webpage as: Array ( [0] => ) The file is NOT empty, and it is formated by line breaks so I don't know what's not working.
  17. bump... still having trouble getting the first function to return the next paragraph
  18. The file is broken up exactly how it needs to be displayed. I am exploding with line breaks. This response helps quite a bit and I'll see what I can do. I get frustrated and just try to move on.
  19. Yes, it's a homework assignment. No, I'm not trying to cheat, so pointing me somewhere is better than just feeding me code, like, "look up how to blah blah" or tell me what I've got wrong? I'm trying to parse a text file of the constitution, add header and <p> tags depending on the first word of the paragraph, then print to an html page. I know I'm supposed to create a function that will return a paragraph, and another function that will return the first word of a paragraph. This is my code, and it completely does not work (obviously I've not included the external html tags) <?php // Opens the constitution text file. $const = fopen("constitution.txt","r"); //Returns an entire paragraph function getParagraph($myfile) { while (!feof($myfile)){ $line = file_get_contents($myfile); $paragraph = explode("\n",$line); } return $paragraph; } //Returns the first word of a paragraph function getFirstWord($myfile) { $pg = getParagraph($myfile); $word = explode(" ",$pg); Return $word[0]; } // Runs through some if statements to determine the tags to use if (getFirstWord($const) === "Article"){ echo "<h2> getParagraph($const)</h2>"; } elseif (getFirstWord($const) === "Section"){ echo "<h3> getParagraph($const)</h3>"; } elseif (getFirstWord($const) === "Amendment"){ echo "<h3> getParagraph($const)</h3>"; } elseif (getFirstWord($const) === "We the People"){ echo "<em> getParagraph($const) </em>"; } else{ echo "<p> getParagraph($const) </p>"; } fclose($const); ?>
×
×
  • 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.