Jump to content

johnwayne77

Members
  • Posts

    156
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.ducoci.ro

Profile Information

  • Gender
    Not Telling

johnwayne77's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hello! I have a json table in mysql which stores questions and its answers for a test. What i want to do is to group the answers to its parent question like this: ex.: User1: question1: answer b, c question2: answer a,d User2: question1: answer c, a question2: answer b, a User3: question1: answer c, b question2: answer d,a Now i want to have a report that shows like this (ordered): question1 : answer c (3) ; answer b (2) ; answer a (1) question2 : answer a (3) ; answer d (2) ; answer b (1) I already decoded the json and with a foreach i get information like this: Question: 3 --> Answer: 1 Question: 29 --> Answer: 147 my code: $i=0; while ($row = mysql_fetch_assoc($sqljson)) { $i++; $json = $row['serialization']; $data = json_decode($json, true); foreach($data as $key1 => $value1) { foreach($value1 as $key2 => $value2) { echo "<b>Intrebare: </b>" . $key1 . " --> <b>Raspuns: </b>" . $value2 . "<br />"; } } echo "<hr>"; if ($i == '3') exit; } any ideas how i can group answers for questions ? i need it for some reporting
  2. heh, the field was INT , that's why i couldn't append any text.. thanks, the code worked also! cheers
  3. what is wrong with this code? $query = "SELECT * from cp_products2"; $doq = mysql_query($query); while ($row = mysql_fetch_assoc($doq)) { $catid = $row['cat_id']; $newcatid = $catid . "mns"; $query2 = "UPDATE cp_products2 SET cat_id = '$newcatid' WHERE cat_id = '$catid'"; $doq2 = mysql_query($query2); echo "categorie veche: " . $catid . " | Categorie noua: " . $newcatid . "<br>"; } it echoes correctly but it doesn't update the fields.. any ideas?
  4. ok, i have : $fname = "data.csv"; $fhandle = fopen($fname,"r"); while (($data = fgetcsv($fhandle, 1000, ",")) !== FALSE) { $oldcat = array("\"40\"", "\"52\"", "\"54\""); $newcat = array("100x", "1000x", "10000x"); $data[2] = str_replace($oldcat, $newcat, $data[2]); } fclose($fhandle); so, i found column 3, searched and replaced the values i want but now... how do i apply the changes to the same csv file ? any ideas? would really be appreciated as i'm running my brains out thanks
  5. this is how i fixed the issue: $r = mysql_query("SELECT cp_products.* FROM cp_products, cp_categories WHERE cp_products.cat_id = cp_categories.cat_id AND cp_categories.cat_parent = '101' ORDER BY cp_products.product_id LIMIT 0, 200"); while ($row = mysql_fetch_assoc($r)) { $csv .= '"'.join('","', str_replace('"', '""', $row)); $pid = $row['product_id']; //echo "hey man " . $pid; $i = mysql_query("SELECT cp_prod_img.img_src500 from cp_products, cp_prod_img WHERE cp_prod_img.prod_id = $pid ORDER BY cp_products.product_id LIMIT 0, 1"); $num_rows = mysql_num_rows($i); if ($num_rows > 0) { $i2 = mysql_result($i, 0); } else { $i2 = "nopic.jpg"; } $csv .= "\",\"" . $i2 . "\"\n"; }
  6. i have a csv with two columns (1) , (2) the columns have identical values in the field set using $content = str_replace($oldcat, $newcat, $content); i need to replace contents only for the (1) column and preserve the (2) columns' original content any idea how i could accomplish that? thanks
  7. could somebody tell me a logic to resolve this issue: i need to export all products from a store (in .csv format) and then import it into another store. 1. all product details are located in one table 2. images currently uploaded (only paths) are located in another table 3. they are linked via a product_id field 4 !!! -> the problem is that a product sometimes has more than 1 picture so I have 3 values for the same product_id in the images table Now, i managed to export the product details via the following script: $table = 'cp_products'; $csv = NULL; /* link identifier from db connection */ $conn_id = dbconn($host, $db_name, $user, $pass); $r = mysql_query("SHOW COLUMNS FROM cp_products"); while ($row = mysql_fetch_assoc($r)) { $csv .= $row['Field'].','; } $csv = substr($csv, 0, -1)."\n"; $r = mysql_query("SELECT cp_products.* FROM cp_products, cp_categories WHERE cp_products.cat_id = cp_categories.cat_id AND cp_categories.cat_parent = '101' ORDER BY cp_products.cat_id LIMIT 0, 200"); while ($row = mysql_fetch_assoc($r)) { $csv .= '"'.join('","', str_replace('"', '""', $row))."\"\n"; } header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv; filename=" . date("Y-m-d") . "_".$table.".csv; size=".strlen($csv)); echo $csv; exit; this would be the select code for adding images too: $r = mysql_query("SHOW COLUMNS FROM cp_products"); while ($row = mysql_fetch_assoc($r)) { $csv .= $row['Field'].','; } $csv .= 'img_src500,'; $csv = substr($csv, 0, -1)."\n"; $r = mysql_query("SELECT cp_products.*,cp_prod_img.img_src500 FROM cp_products, cp_categories, cp_prod_img WHERE cp_products.cat_id = cp_categories.cat_id AND cp_categories.cat_parent = '101' AND cp_prod_img.prod_id = cp_products.product_id ORDER BY cp_products.product_id LIMIT 0, 200"); while ($row = mysql_fetch_assoc($r)) { $csv .= '"'.join('","', str_replace('"', '""', $row))."\"\n"; } my problem is in this condition: cp_prod_img.prod_id = cp_products.product_id + that i need only 1 pic extracted for each product because it extracts only the products that have pictures.. i was thinking if there is something else than "AND" operator in SQL.. something more auxiliar so it won't dump the no-pic products.. i hope you understood the situation.. i am still thinking of a solution.. maybe u have some advices... thanks
  8. this is the solution: Alternative for file() Instead of: <?php $lines = file('http://example.com/'); // display file line by line foreach($lines as $line_num => $line) { echo "Line # {$line_num} : ".htmlspecialchars($line)."<br />\n"; } ?> Use this: <?php $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, 'http://example.com'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); $lines = array(); $lines = explode("\n", $file_contents); // display file line by line foreach($lines as $line_num => $line) { echo "Line # {$line_num} : ".htmlspecialchars($line)."<br />\n"; } ?> found it at https://www.clan-solutions.com/support/index.php?_m=news&_a=viewnews&newsid=5 exact what i needed. thanks and cheers~
  9. uhm.... works with file() but doesn't work with file_get_contents and curl... Warning: Invalid argument supplied for foreach() in /home/metropp0/public_html/newslettertest/sendletter.php on line 58 that's the error
  10. what about importing the mails.txt from another site ... file_get_contents doesn't work any substitute for file() ?
  11. nice, it works! now i'll try to implement a sleep() solution to bypass the limit thanks
×
×
  • 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.