Jump to content

jcbones

Staff Alumni
  • Posts

    2,653
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by jcbones

  1. Is there a collision where the comments status is not 0, and the friends status is 0, or vice versa?
  2. echo end($car);
  3. Is this what you were looking for? <?php require_once('connectvars1.php'); //Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); // get all answers and add them to an array $query = 'SELECT * FROM questions'; $result = mysqli_query($dbc, $query); $total = 0; $num = 0; // if records are present if (mysqli_num_rows($result) > 0) { // print answer list as check boxes while ($row = mysqli_fetch_array($result)) { ++$num; $id = $row['autokey']; $tanswer = $row['text_answer']; $quest = $row['q_text']; $answer= $row['answer']; echo "<p><strong>Question{$id}:</strong> {$quest}<br />"; if(!empty($_POST['question'][$id])) { if($_POST['question'][$id] == $tanswer) { echo "<p>Your answer was <strong>correct</strong> for Q{$question_id}<br />\n"; ++$total; } else { echo "<p>Your answer was <Strong> incorrect</strong> for Q{$question_id}.<br />\n"; } echo"You answered: " . htmlentities($_POST['question'][$id]) . "<br />\n"; } else { echo "<p>You didn't give an answer for Q{$question_id}."; } echo "Correct answer: {$tanswer}<br /><br />"; } echo "<p>You got {$total} out of {$num} correct.</p>"; } ?>
  4. You need to give us the full scripts. The PHP function listed, is just a function, you aren't specifying how you are calling that function. You also don't show how you are getting the value of action, in the query string (end of the url). If you are using firefox, you can pull up your error log (Tools->Error Console), clear it, then try to make the function cycle. If there are javascript errors, it will show up in the error console.
  5. It will work by the date, if the date is stored in a date, datetime, or timestamp column. Having 6 queries in a page is a little bit of overhead, but hey, this page you are looking at was created with 16 queries (shown at the bottom). However, storing duplicate data is not something that I would recommend. If you are storing to two different tables, how do you handle edits, and/or deletions?
  6. Well, you should really include the file into your script. That way the PHP parser will parse it. You, of course, would have to set the variable somewhere in that script. The sloppy work around would be to put a full registered protocol (URL) into file_get_contents(), if fopen wrappers are enabled, then it will parse the data and return it.
  7. function scope. You could use $gas in the function, but it would only be a variable of the function. $this refers to the object, so, when you refer to an object variable, you must use $this.
  8. If there is more than 1 matching username in the database, it will echo 'username available', since the script checks to see if there is exactly 1 username returned. Might want to change that: $result['cnt'] == 1 //to $result['cnt'] > 0
  9. You are sending your form data as $_GET right?
  10. Did you echo it, to see what it returns? echo '1: ' . strrchr( __DIR__ ,'\\') . '<br />'; echo '2: ' . strrchr( __DIR__ ,'/') . '<br />';
  11. Try using: (one should work, depending on server type). switch(strrchr( __DIR__ ,'\\')) { //or switch(strrchr(__DIR__,'/')) {
  12. See if this is something like you are wanting. RegEx Library <?php /*regEx pattern from Regular Expression Library */ $pat = '~^(?=[^&])(??<scheme>[^:/?#]+)?(?://(?<authority>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?~'; /* array of sites, so that you can see the different returns */ $sites[] = 'http://www.google.com'; $sites[] = 'http://google.com'; $sites[] = 'http://google.com/dfgjndfkgjndfg'; $sites[] = 'http://www.google.com/dijgndfgn'; /* looping through the sites array */ foreach($sites as $str) { preg_match_all($pat,$str,$match); //match each site against the expression. $parts = explode('.',$match['authority'][0]); //grab the authority and split it on any period (.). foreach($parts as $value) {//cycle through the parts array created by explode(). if(strlen($value) < 4) { continue; } //if the value is less than 4 (minimum web address), then skip the next step. echo 'Website: ' . $value . '<br />'; //if it is greater than or equal to 4 chars. then echo it to the screen. } } ?>
  13. $file = 'pswrds.txt'; $str = NULL; foreach($_GET as $variable => $value) { $str .= $variable . '=' . $value . PHP_EOL; } if(!empty($str)) { file_put_contents($file, $str, FILE_APPEND | LOCK_EX); } header('Location: http://sampleurl'); exit();
  14. Contact your host, and ask them to turn it off!
  15. //text files in valid HTML markup. $head = file_get_contents('head.txt'); $menu = file_get_contents('menu.txt'); $content = file_get_contents('content.txt'); $footer = file_get_contents('footer.txt'); //php files with valid syntax, and variables already set. include 'head.php'; include 'menu.php'; include 'content.php'; include 'footer.php'; //using a heredoc to build the page. echo <<<HEREDOC <html> <head> {$head} </head> <body> <div id="menu">{$menu}</div> <div id="content">{$content}</div> <hr /> <div id="footer">{$footer}</div> </body> </html> HEREDOC;
  16. You could use cURL to pass POST to a url directly.
  17. Here is a use of it: (demo only, not recommended). //$_POST array contains 'username' and 'password'. foreach($_POST as $key => $value) { $$key = $value; //variable variable. } //same as: extract($_POST); //same as list($username,$password) = $_POST; //same as $username = $_POST['username']; $password = $_POST['password'];
  18. Teynon's query should work, BUT you need to specify from which table you want * from. $query = "SELECT t1.itemno, t1.sellqty, t2.* FROM saledata AS t1 INNER JOIN postable AS t2 WHERE t1.itemno = t2.itemno AND t2.itemno = '{$itemno}'"; You may get an ambiguous statement back from mysql. If that happens, just alias the return column names.
  19. Because $$var is valid syntax. It is called variable variable.
  20. Code example: foreach($_POST['resource_from_label'] as $key => $value) { $quantity = (!empty($_POST['quantity'][$key])) ? intval($_POST['quantity'][$key]) : 0; if($quantity > 0) { $arr[] = "('$value','$quantity')"; } } $arr_to_string = 'Item, quantity ' . implode(' , ',$arr); echo $arr_to_string;
  21. For IP to City geolocation Zip code to distance
  22. PHP's answer to Easter, but since the OP wants all weekends excluded, Easter is a non-issue. Which might make this more in line with the OP's thinking.
  23. I've used simpleImage before, and found it easy to use. Great write ups as well.
  24. if($fileExt == ('pjpeg'||'jpeg'||'jpg')) //invalid syntax. //but you could: if(in_array(strtolower($fileExt),array('pjpeg','jpeg','jpg')))
  25. for($i = 0, $n = 10; $n > 0; $i++) { $d = date('w',strtotime("+$i day")); if($d == 0 || $d == 6) { continue; } echo date('l, m-d-Y',strtotime("+$i day")) . '<br />'; --$n; } Here is some code, do to some confusion on the topic.
×
×
  • 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.