Jump to content

retro

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Everything posted by retro

  1. Oops! I just noticed that I hadn't set the id in the HTML! :-\ It works now - id="btnToggle", same as name. However, when I use $b = $_POST['btnToggle'] after submitting the form, $b doesn't return anything. How can I get around this? *edited* think I'm half asleep today!
  2. Hi, I am a complete newbie at JavaScript, so apologies for this more than likely easy-to-answer question! I took a simple script that toggles a button's value based on whether an option box was enabled or disabled (the button also toggled this) and stripped the option box out. Here is what I came up with: <script type="text/javascript" language="javascript"> function toggle() { if (document.getElementById("btnToggle").value == "OFF") { document.getElementById("btnToggle").value="ON" return } if (document.getElementById("btnToggle").value == "ON") { document.getElementById("btnToggle").value="OFF" return } } </script> I then used a SWITCH statement to give $c a value of "OFF" or "ON" based on a field in a table. I then made the button: <input type="button" name="btnToggle" value="<?php echo $c ?>" onclick="toggle()" /> When the page is loaded, the button correctly displays ON or OFF depending on the field. However, nothing happens when I click the button. I am sure this is in the .value == "OFF" part. How can I remedy this? Thanks in advance for any help offered!
  3. Apologies if there is a glaringly obvious answer to this - I am still a relative beginner with PHP! I have used DATEDIFF in a MySQL query to determine when a date in a db (`date`) falls on the same day as an entered date ($DelDate), but they have to be fortnightly ranges. The query used: This will show fortnightly results, e.g. if `date` was 2008-06-12 (Thursday 12 June) then when $DelDate is 2008-06-12 or 2008-06-26, it would return results, but not if it were 2008-06-19. I now want to be able to do the same thing in PHP - determine whether a date falls on a fortnightly range of another date. I don't know whether it would help, but you could see it as the original date being on an A week, with the weeks alternating A or B, and so I want to determine whether a date is in an A week. (Incidentally, I have already filtered all results to be on that day of the week, so the rest of the week is irrelevant). Can anyone suggest anything? Thanks in advance for any information offered - it is greatly appreciated!
  4. Ahh, never mind... I was thinking too complex! I achieved it with the following: if ($id != '') { } else { $id = $insert; } ?> <meta http-equiv="refresh" content="0;url=contact.php?id=<? echo $id ?>" /> <?
  5. I have a page with a form for entering or editing customer details. This is controlled by using $_GET['id'] and therefore determining whether to create a blank record or edit an existion one (calling the `id` field from the database). This form actions save.php, the code of which is as follows: <?php header("Location: ./"); ?> <? //Connect to DB & check for errors include("dbinfo.inc.php"); $connection = mysql_connect($server,$username,$password); if (!$connection) { echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db($database)) { echo("Database not found<br>"); } //retrieve post data $id = $_POST["id"]; $FirstName = $_POST["firstname"]; $MiddleName = $_POST["middlename"]; $LastName = $_POST["lastname"]; $Town = $_POST["town"]; $Street = $_POST["street"]; $PostCode = $_POST["postcode"]; $houseno = $_POST["houseno"]; $MobilePhone = $_POST["mobilephone"]; $HomePhone = $_POST["homephone"]; $OfficePhone = $_POST["officephone"]; $Email = $_POST["email"]; $Homepage = $_POST["homepage"]; if ($id != '') { //Edit current record $query = "UPDATE customers SET firstname='" . $FirstName . "',middlename='" . $MiddleName . "',lastname='" . $LastName . "', town='" . $Town . "',street='" . $Street . "',postcode='" . $PostCode . "',houseno='" . $houseno . "', mobilehone='" . $MobilePhone . "',homephone='" . $HomePhone . "',officephone='" . $OfficePhone . "', email='" . $Email . "',homepage='" . $Homepage . "' WHERE id=" . $id; } else { //Add new record $query = "INSERT INTO customers(firstname,middlename,lastname,town,street,postcode,houseno,mobilephone,homephone,officephone,email,homepage) VALUES ( '" . $FirstName . "', '" . $MiddleName . "', '" . $LastName . "', '" . $Town . "', '" . $Street . "', '" . $PostCode . "', '" . $houseno . "', '" . $MobilePhone . "', '" . $HomePhone . "', '" . $OfficePhone . "', '" . $Email . "', '" . $Homepage . "' )"; } //Update DB $result = mysql_query ($query) or die("SQL Error: " . mysql_error()); mysql_close(); ?> What I want to do is open up the record once it has been saved. To do this, I need to open the page: contact.php?id=x Where x is the id number. As the id number has not been generated yet (it is an auto increment field in the database), I assume I would have to put $insert = mysql_insert_id(); after the $result at the end. Indeed, when I tried echoing this with the header disabled, it gave me the correct id. However, I cannot get it to redirect to the correct page. I tried using both of the following: header("Location: ./contact.php?id=" . $insert . ""); header('Location: ./contact.php?id='.$insert); And both times, it redirected to contact.php?id= (i.e. it didn't fill in the id number). Is this because $insert is not defined until the end of the document? I tried moving the header code to the end of the document, but it did not like this, giving the following error: Can anyone suggest how I could get this working as intended? Thanks in advance for any advice offered!
  6. Never mind, I sorted it myself. The first part was a simple spelling error, and the second part can be solved with mysql_insert_id(). I have an issue with the second part, but I'll mark this resolved and start again with that!
  7. I have a page, new.php, which either adds a new user to a database, or edits an existing user (depending on how you accessed it.. it uses $_GET['id]). It has various input boxes, as you'd expect for name, address etc. The action for the form is save.php. Here is the content of save.php: <?php header("Location: ./"); ?> <? //Connect to DB & check for errors include("dbinfo.inc.php"); $connection = mysql_connect($server,$username,$password); if (!$connection) { echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db($database)) { echo("Database not found<br>"); } //retrieve post data $id = $_POST["id"]; $FirstName = $_POST["firstname"]; $MiddleName = $_POST["middlename"]; $LastName = $_POST["lastname"]; $Town = $_POST["town"]; $Street = $_POST["street"]; $PostCode = $_POST["postcode"]; $houseno = $_POST["houseno"]; $MobilePhone = $_POST["mobilephone"]; $HomePhone = $_POST["homephone"]; $OfficePhone = $_POST["officephone"]; $Email = $_POST["email"]; $Homepage = $_POST["homepage"]; if ($id != '') { //Edit current record $query = "UPDATE customers SET firstname='" . $FirstName . "',middlename='" . $MiddleName . "',lastname='" . $LastName . "', town='" . $Town . "',street='" . $Street . "',postcode='" . $PostCode . "',houseno='" . $houseno . "', mobilehone='" . $MobilePhone . "',homephone='" . $HomePhone . "',officephone='" . $OfficePhone . "', email='" . $Email . "',homepage='" . $Homepage . "' WHERE id=" . $id; } else { //Add new record $query = "INSERT INTO customers(firstname,middlename,lastname,town,street,postcode,houseno,mobilephone,homephone,officephone,email,homepage) VALUES ( '" . $FirstName . "', '" . $MiddleName . "', '" . $LastName . "', '" . $Town . "', '" . $Street . "', '" . $PostCode . "', '" . $houseno . "', '" . $MobilePhone . "', '" . $HomePhone . "', '" . $OfficePhone . "', '" . $Email . "', '" . $Homepage . "' )"; } //Update DB $result = mysql_query ($query) or die("SQL Error: " . mysql_error()); mysql_close(); ?> I have two problems... 1. Creating a new user works fine. Editing a user puts their details into the input boxes, which can be altered. However, clicking save doesn't update the record. It seems to perform fine (going back to the home page) with no errors, but the records haven't updated. 2. I want to have it so that once the page has been submitted, it goes to the order page (order.php), filling in the customer details automatically. I can do this on an existing contact by using a button with onclick="window.location.href='order.php?id=<?php echo $id ?>'" However, as the ID field (auto incrementing) has not been created in the database, I cannot do this within save.php (or I would edit the header location). Could anyone make any suggestions on either of these problems? Thanks in advance for any advice!
  8. Sorry, that's what I meant. Agreed, this should work. I would imagine it is a file location problem, e.g.: If this script is: ./script.php then the picture would need to be: ./pallettown.jpg or if the script is: ./subdir/script.php then the picture would be: ./subdir/pallettown.jpg If you're on a Linux server, it may bitch about case too - make sure it isn't .JPG instead of .jpg. I would personally use double quotes for an img src location, but the single one should work. Do the pokemon images work?
  9. You need to tell it you're using PHP.... <?php echo("<img src=\"dir1/dir2/" . $row["username"] . "/images/image.jpg /\">"); ?> or <a href="dir1/dir2/<? echo($row["username"]); ?>/images/image.jpg" />
  10. 1. Is it the same picture that would display where it echos "You just found a Rattata"? 2. Does the picture show up there? If yes to the above, note that you are using pallettown.jpg where it does not work, but Pallet_town.jpg where it works!
  11. OOH! That has returned 3 results, missing out record id 4! Thanks very much for the help!
  12. If I choose May 5th, it gives: string(10) "2008-05-08" If I choose May 15, it gives: string(10) "2008-05-15" etc.
  13. Certainly. I'll use phpMyAdmin (incidentally, phpMyAdmin 2.10.0.2, MySQL Server version: 5.0.51a, MyISAM) Query: SELECT * FROM orders LEFT JOIN customers ON ( customers.id = orders.customer ) WHERE ( recur =1 AND DAYOFWEEK( date ) = DAYOFWEEK( '2008-05-08' ) ) OR ( recur =2 AND DATEDIFF( date, '2008-05-08') %14 =0 ) AND date <= '2008-05-08' AND '2008-05-08' NOT BETWEEN holdstart AND holdend Result: As you can see, I substituted $DelDate with 2008-05-08, which is the value for holdend in order id 4.
  14. they are DATE. Yes, the point is that I want any date that isn't between a range. So my thinking was that if holdstart = "" and holdend = "", then everything should be NOT BETWEEN them, i.e. it would ignore that part of the query. I'll try to (over)simplify: Name: John Smith Fred Bloggs Bert Jones Del. Day: Mondays Tuesdays Mondays Holiday: 24-31 May 2008 n/a n/a If I were to run my query for 19 May 2008, it should tell me that John Smith and Bert Jones have deliveries due that day. If I were to run my query for 26 May 2008, it should tell me that only Bert Jones has a delivery. I guess I'm not interpreting how NOT BETWEEN will work correctly. In the above example, I'd feed in 2008-05-26 and it would determine that this lies between 2008-05-24 and 2008-05-31 and not display that record. As this won't work, can you suggest how I can either tweak this, or another way to accomplish the same thing? Thanks!
  15. Apologies for what is probably a basic question - I am quite new to MySQL and still learning! I have a query that filters out records using a calendar input ($DelDate), and determines whether a recurring order is due to be delivered on that date. This query works fine: SELECT * FROM orders LEFT JOIN customers ON ( customers.id = orders.customer ) WHERE ( recur =1 AND DAYOFWEEK( date ) = DAYOFWEEK( '$DelDate' ) ) OR ( recur =2 AND DATEDIFF( date, '$DelDate') %14 =0 ) AND date <= '$DelDate' However, I want to be able to exclude records over a date range, for example if a customer goes on holiday. For this, i have put two fields in the 'customers' table - 'holdstart' and 'holdend'. I tried adding the following to the end of the query: AND '$DelDate' NOT BETWEEN holdstart AND holdend However, it just gave the same four results. Three of these results have no holdstart or holdend values, the other has a holdstart value of 2008-05-08 and holdend value of 2008-05-15. I tried running the query in phpMyAdmin, substituting '$DelDate' with '2008-05-15'. Again, I got the same 4 results. How can I solve this? Thanks in advance for any help offered!
  16. Btown2: Thanks, but I'm OK with the html formatting. Its more the looping to get the data into the table that I'm having problems with! ady01: Thanks for that! I tried it pretty much as-is, changing the database / table info, but I got an error. It said there is an unexpected } - it is the one that appears after $numcolsprinted++; I tried removing the bracket, and all I got was 11! I'm not sure what's going on there! I put the bracket back, and removed the previous one, and there was no output at all! Is this pseudo code, or complete? I notice there's no <table>. I'm not sure whether this is going to do what I want. I'll have a play with it. I notice you're using mysql_fetch_row where I used mysql_fetch_array - I guess this will make a difference, so I'll look into using that. Thanks! One thing I didn't mention - I'd rather have the items as seperate tables. So if you look at my example, it would print one table for Joe Bloggs' order, then print a new table underneath (but with the same layout) for Fred Smith's order. If anyone has any more ideas, I'd love to hear them! Thanks in advance!
  17. You might want to use two text boxes - one for artist, the other for song. So often you find people don't standardize what they write, and with a more obscure artist, it is difficult to tell which is the artist and which is the song! For example, you might get something like: Stomp - Elephant. Is the artist Stomp or Elephant? Of course, if you did this, you would have two fields in your database, and call the two together, e.g.: echo $row["artist"] . " " . $row["title"];
  18. I currently have a 'report' page which displays the results of a query in columns, such as: NameItem 1Item 2Date Joe Bloggs1010/05/08 Fred Smith0210/05/08 These results will be orders on a particular day. I am using the following code: // print table header echo("<table cellspacing=\"0\" cellpadding=\"0\" width=\"500\" class=\"edittable\"> <tr><th>Name</th><th>Item 1</th><th>Item 2</th><th>Date</th></tr>"); // fetch the current row into the array $row while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo("<tr>"); echo("<td>" . $row["FirstName"] . " " . $row["Lastname"] . "</td>"); echo("<td>" . $row["Item1"] . "</td>"); echo("<td>" . $row["Item2"] . "</td>"); echo("<td>" . $row["date"] . "</td>"); echo "</tr>"; } echo("</table>"); However, what I want to output is what will look more like a delivery sheet, as follows: Name: Joe Bloggs Item 1: 1 Item 2: 0 Date: 10/05/08 Name: Fred Smith Item 1: 0 Item 2: 2 Date: 10/05/08 How can I go about doing this?
  19. Thanks! The LEFT JOIN makes perfect sense
  20. Sorry if the answer is glaringly obvious here, but I am very new to MySQL and am basically learning as I go! I have a MySQL4 database, which is standard MyISAM. In the table 'persons' I have fields ID, FirstName and LastName. In the table 'orders' I have ID, customer, date and several Item fields (Item1, Item2 etc.) I am using the following query: $DelDate = $_POST["DelDate"]; $result = mysql_query ("SELECT ID,customer,Item1,Item2,Item3,Item4,Item5,Item6,Item7,Item8,Item9,Item10,date FROM orders WHERE DAYOFWEEK(date)=DAYOFWEEK(' . $DelDate . ')"); $total = mysql_num_rows($result); I then use a while loop to echo the $row data into a table. This works fine. However, the data in 'customer' is a number, which matches 'ID' in 'persons'. I want to display the first and last name instead, by looking these up in 'persons'. My database knowledge comes from Access, so I know I'd do this with relationships. How would I go about creating relationships on my current database, though? I don't want to lose any data currently in the database. I've seen people mention foreign keys, but from what I gather you can't have foreign keys with MyISAM. How can I solve this? Any help would be greatly appreciated. Thanks in advance!
  21. It is listing newest first for me. However, it seems to be skipping some files - curious. Here's a slightly more complex solution.. Revert back to the original code without the $count stuff. Change the test code at the end to this: //test $i = 1; foreach ($images_arr['time'] as $key=>$ftime){ $fname = $images_arr['name'][$key]; echo '<strong>filename:</strong> '.$fname.' <strong>filetime:</strong> '.$ftime.' <strong>i:</strong> '.$i.' <br/>'; if ($i == 15) { echo "qwerty"; break; } $i++; } I'm sure someone will suggest something better, though!
  22. I'm now getting: Line 18 is the line after the query: $total = mysql_num_rows($result); It was working fine on the weekly one. Any ideas?
  23. You could try taking a look at xe.com
  24. I accidentally marked my previous thread as solved (although technically, the original issue was!), so I'll ask my final part of the question here! The database takes an order with a ship date. It also has a tick box to state if the order should be repeated weekly. Thanks to Barand, I have the following query, which works great: SELECT id, customer, baen, date FROM orders WHERE (date = CURDATE() AND recur = 0) OR (DAYOFWEEK(date) = DAYOFWEEK(CURDATE()) AND recur = 1) However, I now need to be able to list orders that are to be delivered fortnightly. So, for example: An order was delivered on Monday 14 April. This order was to be repeated fortnightly. Therefore, on 21 April, it should not show on the list, but it should on 28 April. I have thought about this, and can't see a way of doing it! Perhaps somehow determine whether it is an odd or even week? Or is there an easier way? Thanks in advance for any help - it is greatly appreciated!
×
×
  • 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.