Jump to content

iainlang

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

iainlang's Achievements

Member

Member (2/5)

0

Reputation

  1. Gordon Bennet, that was quick! I didn't even have time to turn round. As always, the answer was staring me in the face, but you pointed me to it. Many thanx.
  2. Please, how do I turn a string whose contents equal, say, "2008-09-05" into "5th September 2008"? I've visited php.net but am just going round and round. (Is there any difference between the php4 and the php5 code?) TIA. Iain.
  3. I've inherited the database of a charity whose volunteeers do Casework with the clients, and, as Caseworkers can occasionally be tackling more than one case at a time, I need to know the last Case number done by each Caseworker. I've never worked with MySQL's MAX() before and I'm haviing notta lotta luck. My (pretty naive, I guess) code follows. The "personnel" fields include - firstname, surname, based, position, telephone, mobile, email The "clients" fields include - caseworker_firstname, caseworker_surname, case_number $count=1; $TableName="personnel"; $Query="SELECT * FROM $TableName WHERE based=\"P\" AND position LIKE \"%Caseworker%\" ORDER BY surname desc, firstname desc"; $Result=mysql_db_query ($DBName, $Query, $Link); while ($Row=mysql_fetch_array ($Result)) { $firstname[]=$Row[firstname]; $surname[]=$Row[surname]; $telephone[]=$Row[telephone]; $mobile[]=$Row[mobile]; $email[]=$Row; $count++; } $original_count=$count; print("<table width=\"900\" cellspacing=\"0\" cellpadding=\"2\" border=\"1\">"); print("<colgroup span=\"6\"><col width=\"17%\"><col width=\"5%\"><col width=\"14%\"><col width=\"14%\"><col width=\"14%\"><col width=\"35%\"></colgroup>"); print("<tr bgcolor=\"#ffffee\" align=\"center\"><td>Caseworker</td><td>Total</td><td>Last Case done</td><td>Telephone</td><td>Mobile</td><td>e-mail</td></tr>"); $TableName="clients"; while ($count>0) { $Query="SELECT max(case_number) AS maximum FROM $TableName WHERE caseworker_surname='$surname[$count]' AND caseworker_firstname='$firstname[$count]' ORDER BY caseworker_surname desc, caseworker_firstname desc"; $Result=mysql_db_query ($DBName, $Query, $Link); while ($Row=mysql_fetch_array ($Result)) { $maximum[]=$Row[maximum]; } $count--; } $count=$original_count; while ($count > 0) { print("<tr bgcolor=\"#ffffee\"><td align=\"right\">$firstname[$count] $surname[$count] </td><td>$count</td><td><a href=\"cli_update_handle.php\">$last_case_number[$count]</a></td><td align=\"right\">$telephone[$count]</td><td align=\"right\">$mobile[$count]</td><td align=\"right\"><a href=\"mailto:$email[count]\">$email[$count]</a></td></tr>"); $count--; } print("</table>"); Any help would be appreciated. Thanx, Iain.
  4. Thank you for your swift response. I do check the PRIMARY BOX radio button, always did, but still get the same error message.
  5. I've searched the Knowledge Base but couldn't find anything which answered my question. I have an auto-increment id field in my tables which (for reasons of displaying the unsigned zerofill in limited screen space) I want to replace with a new auto-increment id field which will, of course, start again at 0. In phpMyAdmin, I delete the existing auto-increment id field and, when trying to install a new one, I get - "ALTER TABLE `help` ADD `id` SMALLINT( 2 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT FIRST MySQL said: #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key " I expect it's something terribly simple and I'm just being stupid. Can anyone help, please?
  6. Magic! Abso-bally-lutely magic! I think I'll start a Feast Day in your honour, name my seventeenth-born after you, raise a graven image, declare a Public Holiday, etc. Dunno how you guys do it. Big thanx.
  7. I've done - include("php-lib/connect_inc.php"); $section_name=trim (strtolower($section_name)); $section_name=mysql_real_escape_string($section_name); // <<----- ; $section_text=nl2br($section_text); $TableName="sections"; $Query="INSERT INTO $TableName (section_id, section_name, section_vis_name, section_heading, section_text, image_filename, title_text) VALUES ('$section_id', '$section_name', '$section_vis_name', '$section_heading', '$section_text', '$file_name', '$title_text') "; $Result=mysql_db_query ($DBName, $Query, $Link) or die(mysql_error()); // <<----- ; include("sec_add.php"); which seems to be accepted wihout question, and $TableName="images_sub_sections"; $TableName="sections"; include("php-lib/connect_inc.php"); $Query="SELECT section_name, section_vis_name FROM $TableName WHERE section_id='$section_id' "; $Result=mysql_db_query ($DBName, $Query, $Link); while ($Row=mysql_fetch_array ($Result)) { $section_name=$Row[section_name]; $section_vis_name=$Row[section_vis_name]; } $sub_section_name=trim(strtolower($sub_section_name)); $sub_section_text=nl2br($sub_section_text); $TableName="sub_sections"; $Query="INSERT INTO $TableName (sub_section_id, section_name, section_vis_name, sub_section_name, sub_section_vis_name, sub_section_heading, sub_section_text, image_filename, title_text) VALUES ('$sub_section_id', '$section_name', '$section_vis_name', '$sub_section_name', '$sub_section_vis_name', '$sub_section_heading', '$sub_section_text', '$file_name', '$title_text')"; print("$Query< br >"); // <<----- ; $Result=mysql_db_query ($DBName, $Query, $Link) or die(mysql_error()); // <<----- ; include("sub_sec_display_short.php"); which produces the line - INSERT INTO sub_sections (sub_section_id, section_name, section_vis_name, sub_section_name, sub_section_vis_name, sub_section_heading, sub_section_text, image_filename, title_text) VALUES ('4000', 'whats_on', 'What's On', 'test_sub_section', 'Test Sub-section', 'Test Sub-section heading', 'Test Sub-section text.', '', '') You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's On', 'test_sub_section', 'Test Sub-section', 'Test Sub-section heading', 'Test' at line 1 Dunno if that makes any sense to you; it doesn't to me.
  8. Sorry - I should have answered your question. The only error I get is that the Sub-section doesn't get inserted into the database table.
  9. Thanx for your swift response. Do you mean like - include("php-lib/connect_inc.php"); $section_name=trim (strtolower($section_name)); $section_name=mysql_real_escape_string($section_name); $section_text=nl2br($section_text); $TableName="sections"; $Query="INSERT INTO $TableName (section_id, section_name, section_vis_name, section_heading, section_text, image_filename, title_text) VALUES ('$section_id', '$section_name', '$section_vis_name', '$section_heading', '$section_text', '$file_name', '$title_text')"; $Result=mysql_db_query ($DBName, $Query, $Link); include("sec_add.php"); 'cos if that's it, it doesn't seem to work. I use HotDog and mysql and php functions are automatically coloured but this doesn't happen with the mysql_real_escape_string thing-y. Sorry to be so thick. Yoooors, Iain. [ I sent phpfreaks 10 sterling at the e-mail address donate@thewebfreaks.com - dunno what that comes to in dollars. ]
  10. Hello. [ BTW - After reading "Have you been helped here?" I've been looking for a "Donate" button but I can't find one that doesn't just take me back to the Home page. Can anyone point me to the right URL? ] Now... I wrote my own small, very simple, naive, CMS scripts to help small charities run their own database-driven website without further aid from anyone outside their organisaton. I have about thirty now and all has been working well for about four years but one theatre Trust wants a What's On section (note the apostrophe - oddly enough, the first time any of "my" little charities thought to use one) and it seems that this forbids the creation of Sub-sections within any Section whose title contains an apostrophe. I've listed my scripts below; can anyone tell me what the solution might be to the apostrophe problem, please? I'm sort'v self-taught and am probably missing something stupid. Thanx. Iain. include("php-lib/connect_inc.php"); $section_name=trim (strtolower($section_name)); $section_text=nl2br($section_text); $TableName="sections"; $Query="INSERT INTO $TableName (section_id, section_name, section_vis_name, section_heading, section_text, image_filename, title_text) VALUES ('$section_id', '$section_name', '$section_vis_name', '$section_heading', '$section_text', '$file_name', '$title_text')"; $Result=mysql_db_query ($DBName, $Query, $Link); include("sec_add.php"); $TableName="images_sub_sections"; $TableName="sections"; include("php-lib/connect_inc.php"); $Query="SELECT section_name, section_vis_name FROM $TableName WHERE section_id='$section_id' "; $Result=mysql_db_query ($DBName, $Query, $Link); while ($Row=mysql_fetch_array ($Result)) { $section_name=$Row[section_name]; $section_vis_name=$Row[section_vis_name]; } $sub_section_name=trim(strtolower($sub_section_name)); $sub_section_text=nl2br($sub_section_text); $TableName="sub_sections"; $Query="INSERT INTO $TableName (sub_section_id, section_name, section_vis_name, sub_section_name, sub_section_vis_name, sub_section_heading, sub_section_text, image_filename, title_text) VALUES ('$sub_section_id', '$section_name', '$section_vis_name', '$sub_section_name', '$sub_section_vis_name', '$sub_section_heading', '$sub_section_text', '$file_name', '$title_text')"; $Result=mysql_db_query ($DBName, $Query, $Link); include("sub_sec_display_short.php");
  11. Aaaarrggghh! I forgot to change the $TableName for the second query; no wonder it wouldn't work. (I shouldn't be allowed out alone, really...) Thanx, Teenfront.
  12. Hello. Some FOOL told a local charity that I was just the boy to take over their web-site, and an even bigger fool said "Yes" when I was asked to do it. So... I've inherited this charity site whose volunteers do Casework among its clients. The task is to list the Caseworkers in alphabetical order with the total number of Cases that each has done throughout the past year. I've tried messing around with GROUP BY and AS and stuff, but I just get deeper and deeper into the Coding Swamp. Unfortunately, I can't change the MySql database structure. Perhaps one of the gurus here can help? <?php include("connection_string"); $n="0"; $year=date("Y"); $year--; $start_date=$year."-".date("m")."-".date("d"); $TableName="personnel"; $Query="SELECT firstname, surname, telephone, mobile, email FROM $TableName WHERE position LIKE \"%Caseworker%\" AND based=\"P\" AND date_case_added >= $start_date ORDER BY surname, firstname "; $Result=mysql_db_query ($DBName, $Query, $Link); while ($Row=mysql_fetch_array ($Result)) { $surname[]=$Row[surname]; $firstname[]=$Row[firstname]; $telephone[]=$Row[telephone]; $mobile[]=$Row[mobile]; $email[]=$Row[email]; $count++; } $count--; $original_count=$count; while ($n<=$count) { $Query="SELECT firstname, surname AS name FROM $TableName WHERE position LIKE \"%Caseworker%\" AND based=\"P\" AND date_case_added >= $start_date GROUP BY name ORDER BY surname, firstname "; $Result=mysql_db_query ($DBName, $Query, $Link); $num=mysql_num_rows($Result); $cases_done[]=$num; } $n="0"; print("<table width=\"800\" cellspacing=\"0\" cellpadding=\"2\" border=\"1\">"); print("<colgroup span=\"5\"><col width=\"8%\"><col width=\"30%\"><col width=\"25%\"><col width=\"23%\"><col width=\"17%\"></colgroup>"); while ($n<=$original_count) { print("<tr bgcolor=\"#ffffee\"><td>$cases_done[$n]</td><td align=\"right\">$firstname[$n] <strong>$surname[$n]</strong> </td><td align=\"right\">$telephone[$n]</td><td> $mobile[$n]</td><td> <a href=\"mailto:$email[$n]\" style=\"text-decoration:none;\">$email[$n]</a></td></tr>"); $n++; } print("</table>"); include("php-lib/footer_admin.php"); ?> Any help would be greatly appreciated. TIA. Iain. (edited by kenrbnsn to add tags)
  13. Nope, it can't be that becos mysql_db_query works everywhere else. I see that my query didn't make it through unscathed - I should have written - $comments=$comments_old." br_within_angle-brackets ".$comments_new;
  14. When trying to update a table, the following works only occasionally; it doesn't work reliably. Can anyone show me where I'm going wrong, please? // $comments_new is the data incoming from the form ; $Query="SELECT comments FROM clients WHERE id='$cli_update_id' "; $Result=mysql_db_query ($DBName, $Query, $Link); while ($Row=mysql_fetch_array ($Result)) { $comments_old=$Row[comments]; } $comments=$comments_old." <br>".$comments_new; $Query="UPDATE clients SET comments='$comments' WHERE id='$cli_update_id' "; $Result=mysql_db_query ($DBName, $Query, $Link); TIA.
×
×
  • 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.