Jump to content


  • Posts

  • Joined

  • Last visited

Profile Information

  • Gender
  • Location
    Liverpool, UK

RebeccaD's Achievements


Newbie (1/5)



  1. Thanks kicken for your explanation. Things like this are a great help to someone with limited knowledge. Whilst we have been having this conversation I have cobbled together a script that does what I set out to achieve. I recognise that it is a bit dirty and written in mysql, but I haven't mastered mysqli or PDO statements yet. <?php include 'configuration file'; // Define variables $tablename = "table name"; $col = "column to interrogate"; $ans = array(); $final = array(); $str = array(); mysql_select_db("database name"); // Count number of entries in column $result = mysql_query("SELECT COUNT(*) FROM $tablename"); $rows = mysql_fetch_row($result); $num = $rows[0]; // Get all the entries into an array $result = mysql_query("SELECT $col FROM $tablename"); $store = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $store[] = $row[$col]; } // Combine all entries in array into one array item for($x=0; $x<=$num-1; $x++) { $str[0] = $str[0]." ".$store[$x]; } // Explode array item $str[0] = explode(" ",$str[0]); // Remove semi-colons from list $ans = str_replace(' ', '', $str[0]); // Determine occurence of each word in list $occurences = array_count_values($ans); // Remove duplicate words $final = array_unique($ans); // Sort A-Z natcasesort($final); // Write results echo "<table border='1'>"; echo "<tr><td colspan='2'>Total Responces: ".$num."</td></tr>"; echo "<tr><td>Condition</td><td>No.</td></tr>"; foreach($final as $i =>$key) { if($i<>0) { $out = ucfirst($key); //Upper case all first letters in case any entered as lower case echo "<tr><td>".$out."</td><td>".($occurences[$key])."</td></tr>"; } } echo "</table>"; ?>
  2. Thanks kicken. The structure of the database is not of my doing. I have a number of surveys on a website constructed using the MachForm application. Unfortunately, although MachForm can present results in various formats, it does not report on any data gathered through text boxes (which are one of the default input types that can be used). I need to etract this data for presentation as results. On a more general issue could you explain why you state that complex data such as this should be broken up please. I have never come across such a suggestion especially when it relates to the input from a text box. Are you suggesting that any such input should be broken up? For instance if an input to a text box required a sentence such as "Mary had a little lamb its fleece was white as snow", that this should be broken up into its constituent words and stored as individual fields in the database?
  3. Many thanks ginerjm and kicken for your helpful replies Regarding the structure of the data, it is input via a textbox. The entry allows the user to enter a list of related things they have (not actually animals!), that is why it is stored as shown and I needed a way of selecting them all so that I can sort them into a list without the duplicates.
  4. Happy New Year from a Newbie. I have data in a MySql database table (let's call it data_table) which is input by users via a form. Their input consists of one or a list of items seperated by spaces. This ends up in one column (let's call it data_col) as in the following example format: id data_col 1 cat 2 elephant giraffe 3 dog rabbit 4 snake cat bird 5 fish dog .. etc. I need help with a PHP script to read only this column into a string variable with which I can then (a) use explode to seperate it into an array containing the seperated words and removing the spaces, if any, at the same time and (b) use array_unique to remove any duplicated words in the array, before finally displaying the array as an A-Z ordered list as below. bird cat (duplicate removed) dog (duplicate removed) elephant fish giraffe rabbit snake Many thanks for any help offered.
  5. I have recently installed PHP, MySQL [server version: 5.5.35-0ubuntu0.13.10.1 (Ubuntu)], Apache Server and phpMyAdmin on my Ubuntu 13.10 PC. I am used to using these to build and maintain websites and associated databases along with cPanel on web servers, but have decided that it would be useful to be able to build and test php pages/MySQL databases locally. The installation of the above went smothly and Apache amd phpMyadmin are working correctly. My document root folder is /var/www which I have chmod to 777. I have copied some files that I also have on a website and exported its associated database and imported it locally through phpMyadmin. The php files render correctly in my browser but I do not seem to be able to link to the database. The connection is controlled by a config file which lists hostname, database name, database user and database password. I am used to setting up databases online through cpanel which gives you all of these parameters. My question is, when setting up databases locally are the database user and database password the same as the user name and password for phpMyAdmin, which for me would be root and <an undiclosed password> ? I don't know of ways of setting up users and associated passwords as you would do through cPanel. Will these values be the same for all databases created or do/can seperate users be created? Many thanks.
  6. Hi. I have written a routine for a person even less able than me ( ), so that they can enter a full URL and a decription about it, then have a ready made HTML href attribute constructed so that they can paste this into a text widget in their WordPress website ( See routine at http://interpretationmatters.com/links). Works perfectly, but if for instance the description entered of the URL contains a single quote e.g. The cat's mother, the resulting attribute has a backslash in it before the single quote e.g. <a href="http://www.my_website.com">The cat\'s mother.</a> What can I use to ensure that any special character's that may appear in the description field ($des) are not preceded (escaped) by a backslash - except a backslash of course which is unlikely to be used? These could include !""£$%^&*()_-{}[]:;'?/>< etc. Code which displays results from the form is: <? $id = $_POST["form_id"]; if($id == 0) { echo ""; } else { $url = $_POST["element_1"]; // Data entered for full URL $des = $_POST["element_2"]; // Data entered for description of URL $linka = "<b><a href=\"". $url. "\">". $des. "</a></b>"; // Add $url and $des to give href attribute which will open in same window/tab $linkb = "<b><a href=\"". $url. "\" target=\"_blank\">". $des. "</a></b>"; // // Add $url and $des to give href attribute which will open in new window/tab echo "<div id=\"form_container\">"; echo "<h1><a>Link Coding</a></h1>"; echo "<form id=\"10\" class=\"app\" method=\"post\" action=\"\">"; echo "<div class=\"form_description\">"; echo "<h2>Results</h2>"; echo "</div>"; echo "<ul >"; echo "<p>Using the cursor highlight either code snippet. Copy (Ctrl+C)) then paste (Ctrl+V) either snippet into the Wordpress Widget</p>"; echo "<p>If link is to appear in the <b>same</b> tab:<br>"; echo "<h3>". $linka. "</h3>"; echo "<p>If link is to appear in a <b>new</b> tab:<br>"; echo "<h3>". $linkb. "</h3>"; echo "<p><input type=\"button\" value=\"New Entry\" onclick=\"window.location.href='redirect.html'; return false;\" /></p>"; } ?>
  7. Thanks to all that replied especially Barand as this suggestion was the simplest and WORKS!! Rebecca x
  8. Hi! I maintain a website for a small UK charity and admit that I am no expert when it comes to PHP . We have a number of MySql databases associated with our site to give login access to restricted areas of the site. Login pages for these were designed by someone before I came along. Our web hosting company has recently migrated our site onto new servers which have PHP installed as a CGI not a module and with the current coding in the pages we are unable link to the databases. They suggested a couple of fixes but they do not seem to work. If anyone can suggest a fix or re-write for this (be as brave as you like) I would be eternally grateful. The coding is generally in this format below (I have replaced info about the server, database, password etc with uppercase labels). Please bear in mind if you reply that you are dealing with a complete novice, but someone willing to learn. Not too complicated or with too much geeky language. Many thanks, Rebecca Dittman Chair The Gender Trust Brighton, UK <?// Open a database connection $mysql_link = mysql_connect("localhost", "SERVER_NAME", "PASSWORD") or die ('I cannot connect to the database, exitting.'); mysql_select_db("DATABASE_NAME"); // Get the correct password from the database if($PHP_AUTH_USER != "" && $PHP_AUTH_PW != "") { $mysql_result = mysql_query("select ROW_1, ROW_2 from TABLE_NAME where ROW_1 = '$PHP_AUTH_USER' and ROW_2 = '$PHP_AUTH_PW' and pending = 0", $mysql_link); $row = mysql_fetch_row($mysql_result); if(mysql_num_rows($mysql_result) != 1) { header('WWW-Authenticate: Basic realm="Gender Trust Members Only Area - Please Enter your Email Address as the Username and your Password"'); header("HTTP/1.1 401 Unauthorized"); print "This page requires authorisation. Either you entered an incorrect email/password combination or your browser does not understand how to submit the credentials required"; exit(); } } else { header('WWW-Authenticate: Basic realm="Gender Trust Members Only Area - Please Enter your Email Address as the Username and your Password"'); header("HTTP/1.1 401 Unauthorized"); print "<table width=80% align=center><tr><td><font face=\"Arial\" size=2 color=\"#000066\"><p> <p><center><font size=4>THIS PAGE REQUIRES AUTHORISATION</center> <p> <p align=center><font size=3>If you are not a member of The Gender Trust please click<br>the <font color=\"ff0000\"><b>GT Home</b><font color=\"#000066\"> link to return to the main site. <p align=center>If you are a member, either you entered an incorrect email/password combination<br>or your browser does not understand how to submit the credentials required.<br> <p align=center>Please contact <a href=\"mailto:EMAIL_ALIAS@gendertrust.org.uk?subject=Login Failure\"><font color=\"#000066\"><b>GT web support</b></a> for advice</td></tr></table>"; exit(); } include("headerM.php"); ?>
  • 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.