Jump to content

innitboy

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

innitboy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I can get it to return the list grouped by the 2nd column with the code below like this 500 - 150 500 -- 148 500 -- 132 however i cannot get it to do this 500 - 430 [code] $query  = "SELECT id, 1stlevelkey,  sum(distinct 2ndlevel) / count(distinct 2ndlevel)  as count2nd     FROM  keywords     group by 2ndlevelkey  ";     $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { print_r($row['1stlevelkey']); echo "-"; print_r($row['count2nd']); echo "<br>";     } [/code]
  2. I have 3 columns of data 500 -- 150 -- 54 500 -- 150 -- 32 500 -- 148 -- 75 500 -- 132 -- 98 I would like it to display this 1. 500 - 430 The sum of the unique rows in 2nd column (150 + 148 + 132 = 430) Should I be looking to make 3 different tables from this data and join them or can i get the sum of the 2nd column filtered by the first column in this same table, Here is some code but its not working Thanks in advance for any help :) [code] $query  = "SELECT id, 1stlevelkey,  FROM  keywords     where 1stlevelkey = '".$stlevelkey."'     group by 1stlevelkey  ";     $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) {     $query  = "SELECT id, 1stlevelkey,  sum(2ndlevel) / count(2ndlevel)  as count2nd FROM  keywords     where 1stlevelkey = '".$firstlevelkey."'     group by 1stlevelkey  ";     $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { print_r($row['1stlevelkey']); echo "-"; print_r($row['count2nd']); echo "<br>";     } } [/code]
  3. ok have found out that this piece of code is causing the problem [code] $feed[$key] = $info;[/code] just not sure what to replace it with to get it to show each key rather than the last key in the array.
  4. am i missing something like this? if ($assoc_index = "my_top_level_tag") { rest of my code }
  5. This script turns all the xml tags into arrays and inputs the relevant data into the field names in my table I cant get it to loop over each result (or top level tag), It only shows and imports the last result in the resultset Would appreciate any help? [code]<?php     include 'library/config.php';     include 'library/opendb.php'; $file = "my-xml.xml"; $feed = array(); $key = ""; $info = ""; function startElement($xml_parser,  $attrs ) {   global $feed;    } function endElement($xml_parser, $name) {   global $feed,  $info;   $key = $name;   $feed[$key] = $info;   $info = ""; } function charData($xml_parser, $data ) {   global $info;       $info .= $data; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "charData" ); $fp = fopen($file, "r"); while ($data = fread($fp, 8192)) !xml_parse($xml_parser, $data, feof($fp)); xml_parser_free($xml_parser); $sql= "INSERT INTO section ( "; $j=0; $i=count($feed); foreach( $feed as $assoc_index => $value )   {   $j++;   $sql.= strtolower($assoc_index);   if($i>$j) $sql.= " , ";   if($i<=$j) {$sql.= " ) VALUES ('";}   } $h=0; foreach( $feed as $assoc_index => $value )   {   $h++;   $sql.= utf8_decode(trim(addslashes($value)));   if($i-1>$h) $sql.= "', '";   if($i<=$h) $sql.= "','');";   }   $query=trim($sql);   echo $value; if (mysql_query($sql)){ echo "success in table creation."; } else { echo "no table created."; } echo mysql_error();   echo $sql; ?> [/code]
  6. I would like to use match against in a query but its not returning any results the only data i have in the column is 3,2,1 I want to match all the records that are 3, doesnt seem to return any results, does match against work with numerical searches? cheers
  7. i have also tried using this and cant get it to work [code]<?php include 'library/opendb.php'; $query = "SELECT productfacilities FROM producttable  "; $result = mysql_query($query); $array = array(); while ($row = mysql_fetch_assoc($result)) { $array = array_merge($array, explode(' <#> ', $row['productfacilities']));     }     $unique = array_unique($array);     print_r ($unique); ?> [/code]
  8. i know i need to change this bit $unique[] = "red pie <#> green pie <#> blue pie <#> yellow pie"; $unique[] = "blue pie <#> yellow pie"; $unique[] = "green pie <#> blue pie <#> yellow pie"; but not sure what to change it to Cheers :)
  9. please help brain is hurting ???
  10. I am just also wondering how to get it to work with the result of a mysql query here is the code i am using [code]<?php include 'library/opendb.php'; $query  = "SELECT productfacilities, productcat, productname FROM producttable WHERE productcat='".$productname."'AND productname='".$productname."' order by productfacilities ASC "; $result = mysql_query($query); $unique = array(); // not sure what to put here $unique[] = "red pie <#> green pie <#> blue pie <#> yellow pie"; $unique[] = "blue pie <#> yellow pie"; $unique[] = "green pie <#> blue pie <#> yellow pie"; echo '<pre>' . print_r($unique,true) . '</pre>'; $unique2 = array_unique(explode(' <#> ',implode(' <#> ',$unique))); echo '<pre>' . print_r($unique2,true) . '</pre>'; ?> [/code] Many thanks :)
  11. hi here is my code. I am very grateful for you taking a look I am not sure where to remove the delimiting or where to combine the arrays <?php include 'library/opendb.php'; $query  = "SELECT rating, productcat, productname FROM producttable WHERE productcat='".$productcat."'AND productname='".$productname."'order by rating DESC "; $result = mysql_query($query); $unique_rows = array(); while (($row = mysql_fetch_array($result)) && (sizeof($unique_rows) < 10)) {   if (!is_null($row) && !in_array($row, $unique_rows) && (strlen($row['rating']) < 20)) {     $unique_rows[] = $row;     $vowels = array(  "," , "&", "-", "'", ";", "(", ")"," ", "-",  "----", "---", "--"," ","_","/",":");             echo "<br>", "<a href=\"http://$cms/".str_replace($vowels, "-", $productcat)."/".str_replace($vowels, "-", $productname)."/rating_".str_replace($vowels, "_", $row['rating'])."/\">".$row['rating']."</a>\r\n";       } } ?>
  12. column 1 is id with the values = 1, 2, and 3 column 2 is pies which has all the delimited fields. If i query the database for rows, it just gives me the array the way each row is displayed in the database. It gives me this e.g. Array1 - red pie <#> green pie <#> blue pie <#> yellow pie Array2 - blue pie <#> yellow pie Array3 - green pie <#> blue pie <#> yellow pie what i would like to do is get all of it in one array e.g. Array1 - red pie <#> green pie <#> blue pie <#> yellow pie<#>  blue pie <#> yellow pie <#> green pie <#> blue pie <#> yellow pie Then I would like to remove the <#> delimiter and make the array unique like this Red Green Yellow Blue make any sense
×
×
  • 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.