Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. That makes no sense. Please elaborate.
  2. 01/01/2009 is not a valid date format. If you have service_date as a varchar field then you have made an error. It must be of type DATE (YYYY-MM-DD) to use operators on. Essentially this is a string '01/01/2009' so how can it be greater or less than another value?
  3. oohhh 17 seconds too late Crayon Violent LOL
  4. use an array to map the values $states = array('la' => 'los angeles', 'ca' => 'california'); $x = "la"; print "State: ".$states[$x];
  5. I reccommend going through some php tutorials on using url parameters and sanitizing them when used in sql, also keeping data persistent through pages using various methods. No offense but sounds like you are a newbie.
  6. Your database is not normalised! If your locations table containing towns/cities has its county as a varchar field then this is bad. You are duplicating data. Again, your database should be laid out as: counties ====== countyId title locations ======= locationId countyId title longitude latitude Imagine you noticed that one of your counties has a spelling mistake. You have to update x number of records in your locations table rather than just 1 in the counties table. The tables should be joined via a foreign key in locations. Your sql to get locations by county should look as follows // countyId 1 = 'Merseyside' SELECT * FROM locations WHERE countyId='1' ORDER BY title ASC NOT SELECT * FROM locations WHERE county='Merseyside' ORDER BY title ASC As you have noticed the second method produces unexpected results when you capitalise the first letter of the county. I hope this helps in future projects requiring databases.
  7. You cant have 2 body tags! <BODY> <BODY OnLoad="checkCount()"> Either <body onLoad="checkCount();"> Or add under your js functions and remove the event handler from the body tag: window.onload = checkCount;
  8. Depends on your server configuration
  9. please provide your connection code
  10. You will +1 to the returned number to get the next Id anyhow so if there is 0 rows the function would effectivly do 0+1 giving you Id 1 function maxnum($table, $column) { $result = mysql_query("SELECT MAX($column) AS maxnum FROM $table"); $row = mysql_fetch_assoc($result); return $row['maxnum'] + 1; }
  11. First select the primary key and a title field from the table and loop out the rows within a form. You will create an array of checkboxes with the primary key as the value i.e. print "<form method='post'>\n"; print "<input type='hidden' name='action' value='delete' />\n"; // select data $result = mysql_query("SELECT id, title FROM table ORDER BY title ASC"); while($row = mysql_fetch_object($result)) { print "<input type='checkbox' name='values[]' value='".$row->id."' /> ".$row->title."<br />\n"; } print "<input type='submit' name='submit' value='delete selected' />\n"; print "</form>"; We then will add the code that does the deletion. This should be right at the top of the page, prior to anything being printed on the screen: // delete button selected if($_POST['action'] && $_POST['action'] == 'delete') { if(count($_POST['values'])) { // delete records mysql_query("DELETE FROM table WHERE id IN(".implode(",",$_POST['values']).")"); // reload page header("Location:abc.php"); exit(); } } The whole script will look as follows <?php // delete button selected if($_POST['action'] && $_POST['action'] == 'delete') { if(count($_POST['values'])) { // delete records mysql_query("DELETE FROM table WHERE id IN(".implode(",",$_POST['values']).")"); // reload page header("Location:abc.php"); exit(); } } print "<form method='post'>\n"; print "<input type='hidden' name='action' value='delete' />\n"; // select data $result = mysql_query("SELECT id, title FROM table ORDER BY title ASC"); while($row = mysql_fetch_object($result)) { print "<input type='checkbox' name='values[]' value='".$row->id."' /> ".$row->title."<br />\n"; } print "<input type='submit' name='submit' value='delete selected' />\n"; print "</form>"; ?>
  12. In this situation I wouldn't use an auto incremental field for your primary key. Prior to inserting a record run a function that gets the next available ID (using SELECT MAX()) and use that in your insert query. You then have the id available wherever you need it.
  13. Have you got your locations organised into counties? i.e counties ====== countyId title locations ======= locationId countyId title longitude latitude Then you only need to select the records from a specific countyId and display map markers
  14. Heres the HTML and CSS. http://www.cssstickyfooter.com/using-sticky-footer-code.html Add an event handler / javascript function yourself to hide it when the x is clicked. This is not hard.
  15. Good question. The fact that it is simply unreadable / editable for a human puts a ? on your question. I have never seen a server side script condensed in this way which makes me believe this is not an approach you would adopt. However client side scripts are a differet matter. I often see HTML, Javascript condensed to speed up their download to the client.
  16. This will be done with Javascript, not PHP
  17. Use this and ammend as necessary. http://www.wallpaperama.com/forums/php-how-to-create-make-multiple-table-columns-from-mysql-database-php-t605.html
  18. You are returning the checked variable from the function so you should use it in the global scope. Your script times out because it is a never ending loop as checked is always empty. $recentQuestions = explode("|", $_COOKIE["Recently_answered"]); while(!$checked) { $rnd = rand(1, 203); $checked = recentQuestionsPop($rnd); } Also, are you sure you want to be treating integers as strings? // strings $checked = "0"; $checked = "1"; // integers $checked = 0; $checked = 1;
  19. As cookies are stored on a users computer they will not expire until the date they are told to expire. To end when a user closes their browser you use sessions.
  20. force of habbit
  21. You would never update a primary key. It is used in the WHERE claus of the update query to define what record to update UPDATE users SET name='joe', email='joe@123.com' WHERE userId='123' I suggest you spend some time on database normalisation
  22. I've not checked those mail headers but the code is cleaner <?php error_reporting(E_ALL); ini_set('display_errors', 1); /** * @author Will Morris * @copyright 2009 */ //assign varible names to POST data //card wanted $card = $_POST['card']; //form info $sendername = $_POST['yourname']; $fname = $_POST['fname']; $lname = $_POST['lname']; $room = $_POST['room']; $sendermessage = $_POST['message']; //logic to get link of card chosen if(strlen($card)) { $file = file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/".$card.".jpg"); } else { echo "You didn't choose a card!"; exit(); } //email part $to = 'will.morris@trilakesmc.com'; $subject = 'Tri-Lakes Medical Center Patient Cheer Card'; $headers = "From: will.morris@trilakesmc.com\r\n MIME-Version: 1.0\r\n Content-Type: multipart/mixed; boundary=\"$bound_text\" Content-Type: image/jpg; name=\"CheerCard.jpg\"\r\n Content-Transfer-Encoding: base64\r\n Content-disposition: attachment; file=\"CheerCard.jpg\"\r\n".chunk_split(base64_encode($file)); $message = "Content-Type: text/html; charset=\"iso-8859-1\"\r\n Content-Transfer-Encoding: 7bit\r\n\r\n Hey ".$fname." ".$lname .", ".$sendername." has sent you a CheerCard.\r\nMessage: ".$sendermessage."\r\nRoom #: ".$room; if(mail($to, $subject, $message, $headers)) { echo 'MAIL SENT'; } else { echo 'MAIL FAILED'; } ?>
  23. The body of the message should come at the end. Not within the message header. Also you have the variable $message used twice. See below: $message .= "\r\nHey ".$fname." ".$lname .", ".$yourname." has sent you a CheerCard.\r\nMessage: ". // this part is bad $message. "\r\nRoom #: ".$room.$bound;
  24. What would they be? PHP's standard session handling is fine in most situations. There are however some cases where you need a custom session handler i.e. database. One example is maintaining sessions accross domains. One con regarding using a database for handling sessions is speed and the size of data being stored. Basic tutorial http://bubble.ro/Creating_a_customized_session_handling_system_in_PHP__part_I.html
  25. The printf() or sprintf() functions may also be easier for you if you have trouble concatinating variables. Look them up on php.net
×
×
  • 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.