Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. There are many date/time function built into MySQL: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html For example, if you're looking to show all podcasts since 2011, you could try something like: $sql = "SELECT * FROM podcasts WHERE YEAR(airdate) > 2011";
  2. For what it's worth, the exit() only happens if all fields are filled out. This might make it a little more obvious: <?php //... if(!$snames) { $errorMsg .= "--- You did not select a name for editing."; } else if(!$family) { $errorMsg .= "--- You did not enter a family name."; } else if(!$given) { $errorMsg .= "--- You did not enter a given name."; } else { exit(); } //... ?>
  3. The problem most likely comes from the following: <?php // Process the form if it is submitted if ($_POST['snames']) { ?> If none of the radio button are selected, this if fails. So the part where the error messages are displayed never gets executed. To test if the form was submitted, you could change the if to: <?php // Process the form if it is submitted if (isset($_POST['submit'])) { ?> Side Note: Due to security issues, it's recommended that you don't use $_SERVER["PHP_SELF"] as the action for forms. Here are some alternatives: http://www.phpfreaks.com/forums/index.php?topic=339673.0
  4. To perform a special action every time the 6th item is reached (and the first item), you could do something like this: <?php //CREATE AN ARRAY OF VALUES TO EXPERIMENT WITH $value_array = array(); for($i=1; $i<=15; $i++) { $value_array[] = rand(1,500); } //LOOP THROUGH THE TEST VALUES for($i=0; $i < count($value_array); $i++) { if($i%6 == 0) { $groupBy = true; } //for every 6th item, we need to group by (includes the first item) else { $groupBy = false; } print ($groupBy) ? "<div>$i: Group By - $value_array[$i]</div>" : "<div>$i: $value_array[$i]</div>"; } ?>
  5. I'm not sure what you mean. For me, having an entire table row, for the average data table, is easier to troubleshoot. But I can see this being an issue if each column contains more than just a simple number. I can see what you mean with being more concerned with image size since that will most likely have a greater impact. My example, comes from back in the days when I converted research reports to HTML. These reports were typically hundredes of pages long with dozens of data tables. When I went from having each column on it's own line to one line per table row, the file size would drop by 100s of kilobytes. Granted, this won't be typically for the average developer out there.
  6. Like the others, I don't worry too much about white space. Producing code that's easy to scan trumps the minimal performance gains you might get. However, I am more concerned with the amount of space added to the HTML code via PHP. This content needs to be downloaded by the visitor who may have a slow Internet connection. For example, I used to output data tables using the following format: <table> <tr> <th scope="col">Val 1</th> <th scope="col">Val 2</th> <th scope="col">Val 3</th> <th scope="col">Val 4</th> <th scope="col">Val 5</th> <th scope="col">Val 6</th> <th scope="col">Val 7</th> <th scope="col">Val 8</th> <th scope="col">Val 9</th> <th scope="col">Val 10</th> </tr> <tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr> <tr> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> </tr> <tr> <td>3</td> <td>3</td> <td>3</td> <td>3</td> <td>3</td> <td>3</td> <td>3</td> <td>3</td> <td>3</td> <td>3</td> </tr> <tr> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>4</td> </tr> <tr> <td>5</td> <td>5</td> <td>5</td> <td>5</td> <td>5</td> <td>5</td> <td>5</td> <td>5</td> <td>5</td> <td>5</td> </tr> </table> The above table results in an HTML file around 1.39Kb. But if the table was condensed so that each row was on one line, the file is reduced to around 1.14Kb. <table> <tr><th scope="col">Val 1</th><th scope="col">Val 2</th><th scope="col">Val 3</th><th scope="col">Val 4</th><th scope="col">Val 5</th><th scope="col">Val 6</th><th scope="col">Val 7</th><th scope="col">Val 8</th><th scope="col">Val 9</th><th scope="col">Val 10</th></tr> <tr><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr> <tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr> <tr><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr> <tr><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr> <tr><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr> </table>
  7. The following code seems to work for me: <?php error_reporting(E_ALL); ini_set('display_errors',1); $city = 'bristol'; $county = 'avon'; $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; $xml_str = file_get_contents($geourl,0); function getWeather($geourl) { $xml_str = file_get_contents($geourl,0); var_dump($xml_str); } getWeather($geourl); ?> Looking at the code you posted earlier, how are you getting the value for $city and $county? It looks like you're just assigning some JavaScript code to the variables. As far as I'm aware, JavaScript and PHP don't play well together since one is a client-side language while the other is server-side. What happens if you dump $geourl below? <?php $city = "<script language='javascript'>document.write(geoip_city());</script>"; $county = "<script language='javascript'>document.write(geoip_region_name());</script>"; $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; var_dump($geourl); //... ?>
  8. Basically, your code would be modified to: <?php //... function getWeather($geourl) { //... } getWeather($geourl); ?>
  9. More information about function arguments can be found here: http://www.php.net/manual/en/functions.arguments.php
  10. If you're looking to hide the number after it's been entered and submitted, you could use something like this: <?php $ccNum = "2222 1111 3333 4444"; print "<div>$ccNum</div>"; $ccNum_lastFour = substr($ccNum, -4); $ccNum = preg_replace("~\d~", '*', $ccNum); $ccNum = substr($ccNum, 0, -4) . $ccNum_lastFour; print "<div>$ccNum</div>"; ?> If you're looking to hide the credit card as it's being typed into the form, you'll need to look into solution using a client-side option like JavaScript.
  11. It's probably an issue with variable scope. Have you tried passing $geourl to getWeather().
  12. That's where you put whatever should happen if no results were found.
  13. Ah, just noticed the $day part. If you're looking to pre-populate the form with a DOB from the database, you need to modify the loop to select the necessary option. Here is one way: <?php $day = 22; print "<select name='day'><option value=''></option>"; for($i=1; $i<=31; $i++) { print "<option value='$i'"; if($day == $i) { print " selected='selected'"; } print ">$i</option>"; } print "</select>"; ?> EDIT - sorry, $i should start at 1...not 0
  14. As Pikachu2000 mentioned, you can store the DOB information using the date type. If you're using MySQL, the following link may be helpful: http://dev.mysql.com/doc/refman/5.1/en/datetime.html As for using PHP to develop the drop-down menus, you could do something like the following to generate the "day" menu: <?php print "<select name='day' value='$day'><option value=''></option>"; for($i=0; $i<=31; $i++) { print "<option value='$i'>$i</option>"; } print "</select>"; ?>
  15. So basically, you want to loop through the content extracted from the database and display a link for each entry. Then you want the user to click each link which would send an e-mail to whoever's entry was clicked. Is that correct?
  16. How many e-mail addresses are we talking about? If there are a lot, you may want to check with your host. They may be blocking activity of scripts which sends out too much mail.
  17. You could utilize the imagecreatefromgif() function: http://php.net/manual/en/function.imagecreatefromgif.php
  18. Ah, should have looked at the if() a little closer.
  19. Try changing the or (||) to and (&&) in the if statement: <?php //... if($HourOn == $HourOn && $MinuteOn > $MinuteOn){ //... ?>
  20. Have you had a look at FPDF? http://www.fpdf.org/
  21. @Pikachu2000 - The code provided doesn't quite work. With the way it's set up, the first item is displayed in its own <div>. Also, an empty <div> is created when there is 1, 6, 11, etc. item(s). For what it's worth, neither solution takes into account the potential that the image array may be blank. Here is an updated solution: <?php //CREATE AN ARRAY FOR TESTING ($_GET['numItems'] is used to dynamically change the number of items in the array without changing the code) $img = array(); for($i=1; $i<=$_GET['numItems']; $i++) { $img[] = "image$i"; } //IF THERE ARE ITEMS IN THE ARRAY, DISPLAY THEM $count = count($img); if($count > 0) { for($i=0; $i<$count; $i++){ if($i == 0) { echo "<div>"; } elseif($i%5 == 0) { echo "</div>\n<div>"; } echo $img[$i]; } echo "</div>\n"; } ?>
  22. You wouldn't need the "!$i == 0" if you use an "ifelse()". <?php //... for ($i=0; $i<$count; $i++){ if($i==0) { echo "<div>"; } elseif($i % 5 == 0) { echo "</div> <div>"; } //... ?>
  23. Have you tried changing the interval to 12? <?php //... $statisctis="SELECT COUNT(user_id) FROM `liked` WHERE ((DATE_SUB(CURDATE(),INTERVAL 12 DAY) <= date_liked) AND site_id='data->site_id') "; //... ?>
  24. What does ajGet() look like? The following code seems to work for me. Of course, I needed to set things up differently since I don't have access to your database and I wanted to isolate the code in question. <?php $id = 1; $aantal = 8; print "<div>$id : $aantal</div>"; print "<div><input type='text' value='$aantal' id='$id' size='2' disabled=disabled/></div>"; print "<div><img src='style/edit-button.png' title='Aanpassen' OnClick=\"document.getElementById('$id').disabled=false;\"/></div>"; print "<div><img src='style/save.png' title='Wijziging opslaan' OnClick=\"window.location='mypage.php?id=$id&aantal='+document.getElementById('$id').value; document.getElementById('$id').disabled=true; name='$id';\" /></div>"; ?> The main change was in the use of "window.location". I also added double quotes around the OnClick attribute value.
  25. What does the code that generates GET variables look like? As a side note, you may want to look into validating the GET variables before using them against the database to avoid SQL injections.
×
×
  • 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.