| ||||||||||||||||||||||||||||||||||
select where statement Posted by bschultz (bschultz), 29 November 2005 I'm running into a problem selecting information from a database that has been entered today. Here's what I have so far...that isn't working:Code:
I'm not getting anything in the html table: Any ideas what I'm doing wrong? Thanks. Posted by admin (Graham Ellis), 30 November 2005 on 11/29/05 at 23:06:16, bschultz wrote:
1. I question the single quotes 2. I question the $ Here's a working use of curdate() in a where: Code:
and this gave (today!!) : Code:
Posted by bschultz (bschultz), 30 November 2005 Thanks Graham...I had been working on other parts of this project all day and my brain wasn't wanting to work by the time I did that part of the script.This is for an online weather cancellation program for our radio announcers. When a school calls in that they will open late because of the weather, the announcer just types it into the website. I still need to figure out an "edit" feature that will display all the announcements so far, and allow you to edit them. That's a bit over my head yet. I'm sure I'll be back when I get time to work on that part. Thanks again Graham. Posted by bschultz (bschultz), 4 December 2005 Can you have an if loop and a while loop in one loop? Here's what I'm trying to accomplish:Code:
No matter if there are rows in the database or not, it never get's past the "if" and always echo's: "There Are No Weather Related Announcements Today". I can't seem to find in the documaentaion if I can put an "if / else" with a "while". Thanks. Posted by admin (Graham Ellis), 5 December 2005 There's no problem putting a while loop within an if conditional, or vice versa. I think your problem lies in:Quote:
Where you're storing the LITERAL TEXT mysql_store_result() into a variable called $rows and then comparing it to the number 1. That text WILL always be less than one, thus the results you're reporting. Not exactly sure I know exactly what your meant to write here, but I know what you have isn't want you wanted! Posted by bschultz (bschultz), 5 December 2005 What I wanted was this:If no records match the select statement (that is above the code I posted) then echo "There are no weather related announcements." If there is a match in the "where" select, echo them in the html table. Brian Posted by admin (Graham Ellis), 6 December 2005 Here's the structure I would choose / prefer to use:$rs = mysql_query("Place your query in here"); $matches = 0; echo ("<table>"); while ($row = mysql_fetch_assoc($rs)) { $matches++; echo ("<tr>".Place your line code here."</tr>"); } if (! $nmatches) { echo ("<tr><td>your NO ANNOUNCEMENT message</td></tr>"); echo ("</table>"); It keeps all the data in the table and it's quick and easy. Also allows you to add a "there were 20 announcements" later if you want to. Posted by bschultz (bschultz), 6 December 2005 Thanks for the help, Graham. That still isn't working. The code below displayed both the result AND the line "There are no weather related announcements" if there was a match. If there wasn't a match, it worked well.Code:
Posted by bschultz (bschultz), 6 December 2005 I got it...this line Quote:
should have been Quote:
Thanks again, Graham. Posted by admin (Graham Ellis), 6 December 2005 Sorry you were a victim of my 5 a.m. typo And glad it's working! Graham Posted by bschultz (bschultz), 6 December 2005 I was wondering what function in PHP the "n" was for...and I couldn't find anything! Then I thought it may have just been a typo...thanks again for the help.I do still need to write the code to be able to edit what has already been entered, but I won't get to that this week...but I will be back Posted by bschultz (bschultz), 13 December 2005 OK...I started working on the script to edit data that's already been entered.Here is what each form field looks like on the edit page Code:
When the enter button is pressed, the form action calls edit_db.php. Here's what that file has Code:
I've used code similar to this in the past, and it worked, but I was updating a direct variable. Now, I'm trying to update "$row[event]" and the edit_db.php script is just deleting the contents...not updating them. I'm sure this is something simple...but I can't seem to find anything. Can someone please steer me in the right direction? Thanks you. Posted by admin (Graham Ellis), 13 December 2005 Where you say "deleting", I'm taking it that you mean that it's replacing the contents with nothing rather than deleting the row? What do you have in variables like $event and $hrs - I'm guessing they contain nothing so that's what's being set. Can you post the extra code that shows how they're set up and / or chek what they've got in them - perhaps by printing their values to the browser as a test.Posted by bschultz (bschultz), 13 December 2005 yes, deleting means replace with nothing...the problem is, there was info in the db before the edit_db.php ran.when viewing edit.php, the record for "School A" shows up as "2 hours late": Code:
After updating and changing "school A" to closed (after edit_db.php ran) I should get this: Code:
But instead the columns for event, hrs, closed and notes are all replaced with no data, so the script reads as "there are no records". The variables $event and such are coming from the database...which this edit_db.php script is taking out the data that was in there and being overwritten with "empty" data. The data that is in the database (before edit_db.php runs) is viewable in the edit.php page in the browser. I'm printing those out with this code in the html form: Code:
I can post the whole code to both pages if you'd like...just let me know. Thanks, as always, for the help. Posted by admin (Graham Ellis), 13 December 2005 I would be REALLY tempted to print out the query that's being run and track it back from there .... I think the query is corruped somehow. Did the form that was corrected contain the information in a correctky viewable form? How is your "Register Globals" set. Forgive me if you've answered some of those before - it's been a long day!Posted by bschultz (bschultz), 13 December 2005 the form (before it is edited) does display correctly prior to the edit_db.php script running. Globals are off. I'll print the query when I get home tonight and get back to you.Brian Posted by bschultz (bschultz), 14 December 2005 Opperator error! Graham, I was laying in bed last night, and it hit me...GLOBALS! The script that I had written a year ago to edit the database was written for a machine with globals ON...I changed Code:
to Code:
and everything worked just fine. Thanks for the help. Goes to show that sometimes one should look at the little things first...and THEN look into the more complicated things. Thanks again, Graham. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| |||||||||||||||||||||||||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |