Jump to content

ryandward

Members
  • Posts

    26
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ryandward's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am just assigning an array to an array, because I am testing whether or not I can build a more generic multidimensional array foreach loop, as opposed to writing it for each selectable_document_element, in my case I have around 25. Obviously in the code, where I plan to place it, the multidimensional arrays will be pulled as variables from the database.
  2. <? $i=1; $analysts[$i] = array(0=>'alpha'); $regions[$i] = array(0=>'beta'); $countries[$i] = array(0=>'gamma'); $provinces[$i] = array(0=>'delta'); $events[$i] = array(0=>'epsilon'); $selectable_document_elements = array ( 0=> analysts, 1=> regions, 2=> countries, 3=> provinces, 4=> events ); foreach($selectable_document_elements as $value) { echo $value; print_r($$value[$i]); echo "</br>"; } ?> I can't seem to call $$value[$i], however when I leave off the [$i] part print_r($$value); I get the individual elements... analystsArray ( [1] => Array ( [0] => alpha ) ) regionsArray ( [1] => Array ( [0] => beta ) ) countriesArray ( [1] => Array ( [0] => gamma ) ) provincesArray ( [1] => Array ( [0] => delta ) ) eventsArray ( [1] => Array ( [0] => epsilon) ) However, I would like to get the 1 part of the array, in this example. Is there a magic trick to calling variable arrays' individual elements?
  3. I am still getting the exact same problem; macro0=Americas¯o1=Southeast+Asia
  4. Oh my god, no. Let me look here.
  5. I need to pass this variable via AJAX, but I cannot seem to implode it properly, everything should be working since I am using UTF-8 encoding, but this: $mrq = (implode("&",$mrqa)); echo $mrq; is giving me: macro0=Americas¯o1=Southeast Asia but I am expecting macro0=Americas&macro1=Southeast Asia
  6. But obviously there are going to be hundreds of these types of matches I need in the text. So, I am using preg_match_all.
  7. Alright here is a snippet from the text, what I am trying to do would be to have it match the bolded text and nothing else: Press Releases: Test results on formaldehyde in noodlefish. December 17, 2009. http://www.info.gov.hk/gia/general/200912/17/P200912170203.htm (accessed January 26, 2010). Formaldehyde found in noodlefish sample. December 17, 2009. http://news.gov.hk/en/category/healthandcommunity/091217/html/091217en05004.htm (accessed January 26, 2010). China – Scallops Contaminated with Paralytic Shellfish Poisoning 27 January 2010 Summary: Pre-packaged frozen half-shell scallops contaminated with Paralytic Shellfish Poisoning (PSP) are being sold at supermarkets in Hong Kong and vicinity. Several cases of PSP have resulted. Synthesis/Analysis: The sample containing the toxin was taken from the Kai Bo Food Supermarket on Wu Kwong Street. The product contained PSP toxin levels of 114 μg/100 g. The current legal allowable level of PSP toxins is 800 μg/kg.
  8. I am trying to match all the text in a document, except the date (\d{1,2} (?!\d)\w+ \d{4}) But, then the string must end when the date begins. (?=(\d{1,2} (?!\d)\w+ \d{4})) I cannot for the life of me figure out how to NOT match a general pattern.
  9. I am trying to invert some arrays, making the x-values y, and the y-values x. I have found the code that works, but I cannot understand for the life of me, I have a multidimensional $data array; that looks like this: row:0 :: Country:Algeria row:1 :: Country:USA row:2 :: Country:Morocco The following code successfully extracts the appropriate 'column' from my array. foreach($data as $value){ $invert['country'][] = $value['country']; } It returns: $invert['country'] = Algeria, USA, Morocco But this makes no sense, it seems more logical that the code should be: foreach($data as $value){ $invert[] ['country']= $value['country']; } Since we are accepting all values of the first array, and then specifying the second array. What am I missing here? Why is it working backwards?
  10. This is a LINK to the page -> http://shoutkey.com/carriage I have a problem of separating MySQL concatenated info, yet still maintaining their relationship to other arrays in the same order. First off here is the MySQL code: $query ="SELECT report,"; $query.="GROUP_CONCAT(DISTINCT docID) AS docIDs, "; $query.="GROUP_CONCAT(DISTINCT analyst) AS analysts, "; $query.="GROUP_CONCAT(DISTINCT region) AS regions, "; $query.="GROUP_CONCAT(DISTINCT country) AS countries, "; $query.="GROUP_CONCAT(DISTINCT topic) AS topics, "; $query.="GROUP_CONCAT(DISTINCT date) AS dates, "; $query.="GROUP_CONCAT(DISTINCT event) AS events, "; $query.="GROUP_CONCAT(DISTINCT link) AS links, "; $query.="GROUP_CONCAT(DISTINCT province) AS provinces "; $query.="FROM reports GROUP BY report ORDER BY dates DESC, docIDs DESC"; The most important thing is to get all attributes about each report. The thing is, each report can have as many records as it must, in order to store various types of information, like, if multiple analysts are working on the report, then each one saves their own record, but when retrieving these records MYSQL concatenates the records, to make it look to the analysts like this Report 1 --- Josh, Rebecca --- Philippines However, my problem is trying to display the reports by country... as you can see http://shoutkey.com/carriage. I have no idea about how to split up the countries, while maintaining their relationship to the $rows pulled from MySQL. I am gonna post the entire code, and let me know if anybody has any ideas. $result = mysql_query($query); $numrows = mysql_affected_rows(); $current = false; while($row=mysql_fetch_assoc($result)) { $dates = $row['dates']; $analysts = $row['analysts']; $provinces = $row['provinces']; $topics = $row['topics']; $regions = $row['regions']; $countries = $row['countries']; $reports = $row['report']; $links = $row['links']; $events = $row['events']; if (!$current){ //first call echo "<h3><a href=\"#\">{$countries}</a></h3>"; //echo first call $current = $countries; echo "<div>" ;//open content div } elseif($current != $countries){ // country has changed echo "</div>"; //close previous content div echo "<h3><a href=\"#\">{$countries}</a></h3>"; //echo subsequent countries $current = $countries; echo "<div><p>" ;//open content div } echo $analysts." ----- ".$provinces." ----- ".$reports; echo "<br /><br />"; } echo "</div>"; ?> </div>
  11. This is a BASH script, I am going to write a Python version sometime next week. I'd be happy if someone critiqued me even I wrote this for work, because there are some guys who have to import the tables we save on MySQL as spreadsheets, for programs like ARCGIS. I am sure there are tons more that could benefit from using MySQL data in a different format. Without further adieu, this is my script I have been working on this evening, and it is VERY helpful. It converts entire tables into Excel readable formats, with no knowledge or effort required to operate. #!/bin/bash ###Convert MySQL files into Excel Files### #Get user info echo -e "Enter MySQL user name..." read User echo -e "Enter MySQL password..." read -s Password #Authentication successful? export Valid=`mysql -u $User -e "show databases;" -p$Password` if [ "$Valid" == "" ] then exit fi echo -e "" echo -e ". . . . . ." ###FOR DATABASES### #Display databases echo -e "Displaying a list of databases on the system" mysql -u $User -e "show databases;" -p$Password #Ask user to pick database echo -e "Which of these databases would you like to use? Or escape [x]" read Dbu if [ "$Dbu" == "x" ] then echo "... See ya!" exit fi #Check to see if database exists export ExistDbu=`mysql -u$User -p$Password -Bse 'show databases'| egrep -c -x $Dbu` echo ". . . . . ." echo "Found $ExistDbu exact match for $Dbu." echo ". . . . . ." #Prompt user to fix error if the selection is invalid while [ "$ExistDbu" == "0" ] do echo "Pick a valid database, or escape [x]." read Dbu if [ "$Dbu" == "x" ] then echo "... See ya!" exit fi export ExistDbu=`mysql -u$User -p$Password -Bse 'show databases'| egrep -c -x $Dbu` echo "Found $ExistDbu exact match for $Dbu." done ###FOR TABLES### #Display Tables echo -e "Displaying a list of tables on the $Dbu database" mysql -u $User -e "show tables in $Dbu;" -p$Password #Which table? echo -e "Which of these tables would you like to use? Or escape [x]" read Table if [ "$Table" == "x" ] then echo "... See ya!" exit fi #Check to see if Table exists export ExistTable=`mysql -u $User -e "show tables in $Dbu;" -p$Password| egrep -c -x $Table` echo ". . . . . ." echo "Found $ExistTable exact match for $Table." echo ". . . . . ." #Prompt user to fix error if the selection is invalid while [ "$ExistTable" == "0" ] do echo "Pick a valid table, or escape [x]." read Table if [ "$Table" == "x" ] then echo "... See ya!" exit fi export ExistTable=`mysql -u $User -e "show tables in $Dbu;" -p$Password| egrep -c -x $Table` echo "Found $ExistTable exact match for $Table." done ###NAMING CSV### #Reuqest name for CSV echo -e "Below is a list of currently existing files" ls ~/Documents echo ". . . . . ." echo -e "What would you like to name the CSV? Or escape [x]" read Csv if [ "$Csv" == "x" ] then echo "... See ya!" exit fi LocFile=~/Documents/$Csv.csv while [ -a $LocFile ] do echo -e "That file name already exists, please pick a new name, or escape [x]." echo -e ". . . . . . ." read Csv if [ "$Csv" == "x" ] then echo "... See ya!" exit fi LocFile=~/Documents/$Csv.csv done echo "Writing table $Table from the $Dbu database." mysql -u $User $Dbu -B -e "select * from \`$Table\`;" -p$Password | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > ~/Documents/$Csv.csv echo "Your new file is located at $LocFile"
  12. I have no idea why, I did have to remove all the .'s from the code for the divs to work properly.. <div id="accordion"> <?php //Delcare variable $info $region = $country = NULL; $query = "SELECT * FROM regions"; $result = (mysql_query($query)); $currentregion = false; while ($row=mysql_fetch_assoc($result)) { if (!$currentregion) //first call { echo "<h3><a href=\"#\">{$row['region']}</a></h3>"; //echo first call $currentregion = $row['region']; echo "<div>" ; } elseif($currentregion != $row['region']) // region has changed { echo "</div>"; //close last region div echo "<h3><a href=\"#\">{$row['region']}</a></h3>"; //echo subsequent regions $currentregion = $row['region']; echo "<div><p>" ; } echo $row['country']."<br />"; }// end DB loop echo "</p></div>"; //close last div ?>
  13. Apparently using the . to tie code together is messing with the divs for some reason... working on it now
  14. <?php $region = $country = NULL; $query = "SELECT DISTINCT region FROM regions"; $result = (mysql_query($query)); while ($row=mysql_fetch_assoc($result)) { $region = "{$row['region']}"; $deleteimg = "http://www.veryicon.com/icon/png/System/Float/Delete.png"; $accord = "<h3><a href=\"#\">$region</a></h3>"; $accord .= "<div>"; $accord .= "<p>"; $query=mysql_query("SELECT country FROM regions WHERE region='$region'"); while($row=mysql_fetch_assoc($query)){ $country = "{$row['country']}"; $delete = "<a href=\"delete.php?region=".$region."&country=".$country."\"onclick=\""; $delete .= "return confirm('Are you sure you want to delete?')\">"; $delete .= "<img src=".$deleteimg." height=\"20\"/></a>"; $accord .= $delete.$country."<br />"; } $accord .= "</p>"; $accord .= "</div>"; echo $accord; } This code looks the best, I am still trying to figure out where the divs when awry in the other coding.
  15. I am using the very last one Spiderwell's modification of yours Mikosiko
×
×
  • 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.