Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. When submitting the form, does the URL change when you enter data vs leaving the field blank? In other words, when you hit the submit button in both senerios does the URL stay the same? Is this form on a WordPress website? If so, you may want to also ask the WordPress forum: http://wordpress.org/support/ Note that I'm not very familiar with WordPress yet. I have attempted to do some PHP things with WordPress that work for a "normal" website, but for whatever reason they didn't work in the WordPress environment.
  2. If the ID should always be a number, you could check to make sure it's a number before querying the database. ... if(preg_match("/^\d+$/", $_GET['id'])) { ... This will stop queries for things like: index.php?id=a
  3. I'm not sure what you mean. Doesn't this: $id = $_GET['id']; declare the variable. If the variable exists, why would if($id != "") generate an error?
  4. I don't see any problems with using if($id != ""); that's what I typically use. Note that if you chose to use the empty() function make sure you're aware that $id=0 will be considered empty. It shouldn't matter, you'll just need to have a page called "home.php". The id part just passes a variable.
  5. I'm not sure what's going on with "LeftThumb" and "RightThumb". But if you're trying to display one thumbnail per loop, you want to utilize the $cd variable in the loop. For example: for($cd=0; $cd < $numberofthumbnails; $cd++) { $displaythumbs . '<div class="ThumbnailHolder">'; $displaythumbs . '<div><a class="group" href="../../../Images/Lighthouses/Beachy-Head/' . $cd . '.png"><img src="../../../Images/Lighthouses/Beachy-Head/Mini/Thumbnail-' . $cd . '.png" width="430" height="200" alt="Thumbnail ' . $cd . '"></a></div>'; $displaythumbs . '</div>'; }
  6. Based on the snippet the form fields look to be the same from product to product. So you could look into creating an associative array for all the different products. Then use a loop to display them.
  7. This should work: <?php ... if ($bf->owner == "$username" || $bank->owner == "$username" || $casino_slots->owner == "$username" || $casino_roul->owner == "$username" || $bj->bjowner == "$username" || $airport->owner == "$username") { echo"<tr><td><a class='menuLink' href='myproperties.php' onMouseDown='return false;' target='main'>&#8226; My Properties</a></td></tr>"; } ?>
  8. First we created a variable called "$separator" and made sure it was blank. $separator = ''; Then in the loop, we display whatever "$separator" holds along with the "subject_name". Note that the first time through the loop "$separator" will be blank. Every other time it will contain ', ' which is assigned after the echo statement. ... echo $separator . $row3['subject_name']; $separator = ', '; ... Hopefully that makes sense, let me know if it doesn't.
  9. And yet another option: $separator = ''; while($row3 = mysqli_fetch_array($data3)) { if($row3['level_id'] == 2) { echo $separator.$row3['subject_name']; $separator = ', '; } }
  10. So basically, you want the values from all the boxes that are checked? If so, the first problem is that you'll need to change the checkbox code. Your current code has four checkboxes with the same name. So when the data is sent back to the server you'll only have one value if more than one is checked. <input type="checkbox" name="genre" id="genre" value="fighting" />fighting <input type="checkbox" name="genre" id="genre" value="school life" />school life <input type="checkbox" name="genre" id="genre" value="king" />king <input type="checkbox" name="genre" id="genre" value="him" />him Instead you'll want the checkboxes to have different names and ids. <input type="checkbox" name="genre1" id="genre1" value="fighting" />fighting <input type="checkbox" name="genre2" id="genre2" value="school life" />school life <input type="checkbox" name="genre3" id="genre3" value="king" />king <input type="checkbox" name="genre4" id="genre4" value="him" />him Now you'll have four different variables to work with in your script: echo $_GET['genre1'] . ', '; echo $_GET['genre2'] . ', '; echo $_GET['genre3'] . ', '; echo $_GET['genre4'] . ', '; Note that if your form is set to method="post" you'll need to change the above variables to $_POST['genre1'], etc.
  11. You could use some Javascript and CSS to hide the <div>. Add some CSS to the page: <style type="text/css"> .active { display:block; } .inactive { display:none; } </style> If you're <div> doesn't already have an ID, create one. You'll also need to default the class to "active" if you want it to be shown by default. For example: <div id="contentToBeHidden" class="active">...</div> Now you just need to create a JavaScript funtion to deal with the onclick (Example: <a href="#" onclick="changeRecentPosts()">Test</a>): <script type="text/javascript"> function changeRecentPosts() { //IF THE DIV IS CURRENTLY SHOWING, HIDE IT if(document.getElementById('contentToBeHidden').className == 'active') { document.getElementById('contentToBeHidden').className='inactive'; //ELSE...THE DIV IS HIDDEN, SHOW IT } else { document.getElementById('contentToBeHidden').className='active'; } } </script> Here my entire test script: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function changeRecentPosts() { //IF THE DIV IS CURRENTLY SHOWING, HIDE IT if(document.getElementById('contentToBeHidden').className == 'active') { document.getElementById('contentToBeHidden').className='inactive'; //ELSE...THE DIV IS HIDDEN, SHOW IT } else { document.getElementById('contentToBeHidden').className='active'; } } </script> <style type="text/css"> .active { display:block; } .inactive { display:none; } </style> </head> <body> <p><a href="#" onclick="changeRecentPosts()">Test</a></p> <div id="contentToBeHidden" class="active">Content to be hidden</div> </body> </html> Let me know if you have any questions.
  12. You could remove the link based on the location of the http:// (or https://) and the location of the first space after the position of the http:// part. Note that this will fail if there is a space in the link. http://www.example.com/my page.html
  13. What is "changeRecentPosts()" supposed to do?
  14. Sorry about that, for the error 404 page we use: getenv("REQUEST_URI")
  15. In addition to what was already suggested, is there a reason you're displaying this information in the <head> section of the page?
  16. Using "\s" seems to works for me; I just added it before and after the "[-/.]" parts: if(preg_match("~^(0?[1-9]|1[012])\s[- /.]\s(0?[1-9]|[12][0-9]|3[01])\s[- /.]\s(19|20)[0-9][0-9]$~", $_GET['date'])) { echo 'match'; } else { echo 'no match'; }
  17. No problem. If you're looking for a quick reference for regular expressions, I find the following resource useful: http://weblogtoolscollection.com/regex/regex.php
  18. Just to clarify, with the following code: if(preg_match('/nprezident/,/prezident/', $ex)){ Are you looking for "nprezident" or "prezident" in $ex? If so, you'll want to change the code to: if(preg_match('/(nprezident|prezident)/', $ex)) {
  19. O' ya, I remember those days. Thanks for the clarification.
  20. @dragon_sa Just curious, why is it good practice to check the request method? Isn't it enough that data was passed through $_POST? if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['email'])) {
  21. Using the mysql_num_rows() function should work if you do something like this. ... // select info from comments database $result3 = mysql_query ("SELECT count(*) FROM $table_name3 WHERE id='$post_id' ORDER BY id DESC LIMIT 1") or trigger_error("A mysql error has occurred!"); if (mysql_num_rows($result3) > 0 ) { // display number of comments echo 'Number of comments: ' . mysql_num_rows($result3); while($row = mysql_fetch_array($result3)) { extract($row); ... Note that you'll probably need to remove the "LIMIT 1" part since you'll only get one result every time. You probably also don't need the count() function in the query.
  22. You should be able to break apart the URL with explode(): //GET THE CURRENT URL $url = $_SERVER['PHP_SELF']; //BREAK APART THE URL $urlPieces = explode('/', $url); //LOOP THROUGH THE URL PIECES foreach($urlPieces as $currPiece) { echo "<li>$currPiece</li>"; } You'll need to replace the echo statement in the foreach loop with whatever formatting you need to get the search query. Then just redirect the page.
  23. No problem, glad everything worked out in the end.
×
×
  • 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.