Jump to content

johnwayne77

Members
  • Posts

    156
  • Joined

  • Last visited

    Never

Everything posted by johnwayne77

  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
  12. ok, this is my situation: i have my newsletter database on mysite1.com (which i can export to a .txt file) the inconvenient is that i cannot send more than 200 messages per hour from mysite1.com so i decided to move the newsletter system to mysite2.com where i can send 500+ messages. my current newsletter was gathering mails from sql but now i have to loop into a .txt file for mails and send mail by mail.. i don't have any idea how to do that.. here are some parts of my current newsletter: $getlist="SELECT * from news where inactiv = '0' order by email ASC"; //select e-mails in ABC order $getlist2=mysql_query($getlist) or die("EROARE: mysql"); while($getlist3=mysql_fetch_array($getlist2)) { mail(....) } how would i do the same thing while replacing sql with a txt file?
  13. i have some data in a .txt file. e.g.: codes1 codes2 codes3 etc. sometimes i may have blank rows inside: codes1 codes2 codes3 codes4 etc. i serve these codes using fwrite command. can i specify to eliminate blank rows?
  14. i got it: $ago = 2; // ore $timestamp = time() - ($ago * 3600); $final = date("Y-m-d H:i:s", $timestamp); works fine
  15. i'm working on a cron job function i have an orders table with 'date_added' field like this: date_added : 2009-02-28 07:19:33 i want to add two hours to the date_added value... then after i have the date_added+2 hours in a variable i want to perform different tasks.. but that's my main condition.. how do i add two extra hours to a already added date? i managed to add two extra hours to current date.. but that doesn't help.. : echo date("Y-m-d H:i:s", time()+((60*60)*2)); thanks
  16. great, {cycle} from smarty did all the job
  17. my bad, i thought it was different for foreach now i'm reading about smarty guidelines as i need to implement the foreach incrementation through smarty thanks for the support dude! and sorry for double posting
  18. i have a classified system in which i need to implement a banner system i want to have ads after first 5 listedclassifieds i have a foreach command which lists my classifieds i don't know how to add one banner after each 5 classifieds listed.. something like incrementing var $i++ for a while loop i could have this $i = 1; while($row = mysql_fetch_array($result)){ $i++ //echo table if($i == 5){ //echo banner $i = 1; } } but i don't know what i need for a foreach loop.. any ideas?
  19. great... i'm not sure how to use the increment in the while because i have a smarty template. i tried: {php} $i = 1; {/php} {foreach item=ad from=$ads} {php} $i++ {/php} <tr class="{cycle values=",alt"}"> <td class="pointer"><a href="{$ad.LINK}" title="{$ad.TITLE|escape}"> {if $ad.SPECIAL}{/if}<b>{$ad.TITLE}</b></a> (<span class="pretrosu">{$ad.PRET}</span>) <br /> {$ad.DESCRIPTION|truncate:150:"...":true} - <a href="{$ad.LINK}" title="{$ad.TITLE|escape}">detalii...</a>{if $ad.SPECIAL}{/if}</a><br /></td> <td><div align="center">{$ad.REGDATE}<br /> {$ad.IMAGEYESNO}</div></td> </tr> {if $i == 5} <b>hi</b> {php} $i = 1; {/php} {/if} but no luck.. any advices?
  20. i have a classifieds system which i recently launched it. i get each classified in the system by ---while($row = mysql_fetch_array($result))--- which loops until it reaches the end of the table i really need to place ads in the classified page, let's say after 5 classifieds i need a banner placed how can i halt loop to insert code then continue loop any ideas?
×
×
  • 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.