Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. For the first part of your quetions, you could use a foreach() loop to create the associative array. For example: <?php //INITIALIZE VARIABLES $originalArray = array('meat', 'veggies', 'candy'); $newArray = array(); //CREATE THE ASSOCIATIVE ARRAY foreach($originalArray as $currItem) { $newArray[$currItem] = ''; } //SHOW VARIABLES var_dump($originalArray) . '<br />'; var_dump($newArray); ?>
  2. There may be other issues, but the thing that jumps out at me is the use of double quotes inside of a double quoted string: <?php //... echo "<video class="jwplayer" src=".$info['path']." width="252" height="250"></video>"; //... ?> You need to escape the quotes, switch to a single quoted string, or use single quotes for your attributes. For example: <?php //... echo '<video class="jwplayer" src=' . $info['path'] . ' width="252" height="250"></video>'; //... ?>
  3. Ah, so you can use array syntax on regular variables. But it treats the variable as an array of characters. To see what happens, try this out: <?php $test = 'abs'; print $test['test'] . '<br />'; print $test; ?> That would explain why you're only getting the first character.
  4. Since $login doesn't seem to be an array, it would be written as: $_SESSION['login'] = $login; I'm not sure where $username comes from, but it's probably not an array... $_SESSION['username'] = $username;
  5. Is there a reason you're using array syntax here: <?php //... $_SESSION['login']=$login['login']; $_SESSION['username'] = $username['username']; //... ?> Maybe I'm missing something, but isn't $login a plain variable. Also, where does $username come from?
  6. Have you tried setting the from address in the headers portion? More information can be found under example 2 in the PHP manual for mail(): http://php.net/manual/en/function.mail.php Not always. I've had plain-text e-mails take hours before they're sent by the host...although it usually doesn't take that long. Maybe the mail servers are overloaded at the moment...
  7. Is there a reason, you need JavaScript to maintain the table? You could just manually maintain the table in the HTML code. Also, does it need to be a web page? Maybe you could use Excel or some other spreadsheet software.
  8. Other than the duplicate entries, is "SessionId" ever the same...for different courses? If not, you could use that field when creating the array. If the session ID is already in the array, don't add another. array_unique() doesn't seem to work for multidimensional arrays, but that may provide a clue. The search results for "php array_unique multidimensional array" might be helpful: http://www.google.com/search?q=php+array_unique+multidimensional+array
  9. Note that using $_POST isn't that much more secure. For example, someone could just download your form code; tamper with it; point it to where the form is normally submitted; click the submit button. It may not be as quick as messing with the $_GET variables, but it's not that complicated.
  10. If you don't want to add an anchor tag, the following code: #navlist a:link#current, #navlist a:visited#current, #navlist a:hover { border-bottom: 4px solid #66733f; padding-bottom: 2px; background: transparent; color: #4F4F4F; } /* this line's the style for the current page link */ ...could be changed to: #navlist #current, #navlist #current, #navlist a:hover { border-bottom: 4px solid #66733f; padding-bottom: 2px; background: transparent; color: #4F4F4F; } /* this line's the style for the current page link */ Note that the last part doesn't use the "current" ID, so I left that as is. Let me know if you would prefer to add the anchor tag.
  11. Ah, didn't even look at the PHP. The problem is most likely due to adding the ID of "current" to the <li> tag and not <a>: $menu=preg_replace("|<li><a href=\"".$base."\">(.*)</a></li>|U", "<li id=\"current\">$1</li>", $menu); Either you need to utilize the anchor tag here: "<li id=\"current\">$1</li>" ...or change the CSS formatting so that it's applied to the list item tag.
  12. Are you getting an error?
  13. Instead of using dirname(), have you tried using $_SERVER['DOCUMENT_ROOT']? For example: <?php $includePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $arrPage['include']; ?>
  14. Sorry, I don't have an answer for the question. Have you tried searching for "php mail attachment"...there seems to be a few tuts on the subject: http://www.google.com/search?q=php+mail+attachment The main reason for responding was to caution you about using PHP_SELF as the form action. Here is why: http://www.mc2design.com/blog/php_self-safe-alternatives
  15. How are you adding the "current" ID to the code? The CSS seems to work for me when adding the ID as follows: <ul id="navlist"> <li><a href="index.php">Home</a></li> <li><a href="products.php">Products</a></li> <li><a href="services.php">Services</a></li> <li><a href="about.php" id="current">About Us</a></li> <li><a href="contact.php">Contact Us</a></li> </ul>
  16. No problem, glad to hear it's working. Based on the original post: Maybe the first attempt didn't include the quotes around female... For example, this won't work: <?php $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `users` WHERE gender=female"); //... ?>
  17. Maybe. The first thing that you'll want to look at is your <table> tag. For example, if you create a new page with the following code: <table> <tr><td>test</td><td>test</td></tr> <tr><td>test</td><td>test</td></tr> <tr><td>test</td><td>test</td></tr> </table> <table cellpadding="0" cellspacing="0"> <tr><td>test</td><td>test</td></tr> <tr><td>test</td><td>test</td></tr> <tr><td>test</td><td>test</td></tr> </table> Note the differences between the two tables. As for the code, the only difference is the table attributes.
  18. Which query is that supposed to be added to? Note that the following description of the WHERE clause might be helpful: http://dev.mysql.com/doc/refman/5.0/en/where-optimizations.html
  19. The WHERE clause would go after the FROM: <?php $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `users` WHERE gender='female'"); //... ?>
  20. The problem is likely caused by the existing for loop(s) which displays the data. Instead of using the foreach code that I provided as is, you'll need to adapt it to fit the existing code. I wish I could be of more help, but I don't have a lot of time to dig through the entire script. :'( If you have more questions, I'll do my best to answer them.
  21. The following portion of the code isn't necessary since you already have an array: <?php //CREATE AN ARRAY TO EXPERIMENT WITH $testData = array(); $numOfItems = 25; for($i=1; $i<=$numOfItems; $i++) { $testData[] = "item$i"; } ?> It was just provided for you to experiment with the code and/or customize the code to meet your needs. Note that the code provided in the previous replies doesn't utilize table rows/columns. After removing the test array code above, you'll need to replace $testData below with whatever variable you're using that contains the array to be broken into chunks: <?php //... foreach($testData as $currValue) { //... ?> Note that the foreach loop needs to go after whatever code you are using to create the array to be broken. Hopefully that helps. :-\
  22. My previous code only splits the test data once. If you want to break the array every 15 entries, you could do something like this: <?php //CREATE AN ARRAY TO EXPERIMENT WITH $testData = array(); $numOfItems = 50; for($i=1; $i<=$numOfItems; $i++) { $testData[] = "item$i"; } //INITIALIZE VARIABLES $count = 0; $maxPerList = 15; //LOOP THROUGH THE TEST DATA echo "<ul>"; foreach($testData as $currValue) { //IF WE'VE REACHED THE CUTOFF POINT if($count == $maxPerList) { //CLOSE THE PREVIOUS LIST AND START A NEW ONE echo "</ul>"; echo "<ul>"; //RESET THE COUNTER $count = 0; } //DISPLAY CURRENT VALUE echo "<li>$currValue</li>"; //INCREMENT COUNT $count++; } echo "</ul>"; ?> Note: I changed the default of $count to 0 so that it breaks after 15...instead of 14.
  23. What does your <table> tag look like...and any CSS associated with it?
  24. This isn't exactly what you're asking for, but it should give you an idea of how to break an array: <?php //CREATE AN ARRAY TO EXPERIMENT WITH $testData = array(); $numOfItems = 25; for($i=1; $i<=$numOfItems; $i++) { $testData[] = "item$i"; } //INITIALIZE VARIABLES $count = 1; $cutOffPoint = 15; //LOOP THROUGH THE TEST DATA echo "<ul>"; foreach($testData as $currValue) { //IF WE'VE REACHED THE CUTOFF POINT, START A NEW LIST if($count == $cutOffPoint) { echo "</ul>"; echo "<ul>"; } //DISPLAY CURRENT VALUE echo "<li>$currValue</li>"; //INCREMENT COUNT $count++; } echo "</ul>"; ?> Note that the code will display the first 14 items in the first list. Then displays the rest in a secondary list.
  25. Have you looked into ctype_digit? http://php.net/manual/en/function.ctype-digit.php
×
×
  • 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.