Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi I am trying make one script for opencart import. I am almost done but last few line dont work and I couldnt solve it. here are that lines

$co="SELECT * FROM oc_coupon";
$navrat=mysql_db_query("$database", $co, $spojeni);
$i=0;
while (list($coupon_id) = mysql_fetch_row($navrat)):
$pole2[]= $coupon_id;


while($i == count($pole1)):
$vysledek1 = mysql_query("INSERT INTO oc_coupon_product (coupon_id, product_id)   VALUES('$coupon_id','$pole1[$i]')",$spojeni);
$i = $i+1;

endwhile;

endwhile;

I check rest of the code and everything is okey so problem must be in this lines, any ideas? Rest of code is here http://pastebin.com/E7tYW7qs

share|improve this question
2  
What exactly does not work? What do you expect and what is currently happening? – Sirko 21 hours ago
It shoult get the coupon_id from database table, and save it to another table where are coupon_id and product_id rows. It should look like here prntscr.com/19j5mz but in product id shouldt be 0 but value from array $pole1[$i] In $pole1[$i] are many values it should take all of them and saving them under one $coupon_id. When is $pole1[$i] on the end it sould take next value from $coupon_id and make the same thing like before with the same values from $pole1[$i] and currently is happening nothing. when I add echo before that cykle or after echo is working but not the second while cykle – Martin Zigi Ziegler 21 hours ago
Excuse me. I am an OpenCart developer (or consider myself as to be - not the one that creates it). And if this code (you have showed us) is for OpenCart (or it's extension), I would like to very kindly ask You to stop programming at all. OpenCart could be considered itself as a framework or platform that every developer should follow it's standards and get maximum of all of its functionality as possible. Doing pure mysql_*, forgetting about the MVC, this all hurts! Maybe You should learn better programming in PHP prior to developing anything for OpenCart. – shadyyx 20 hours ago
Well that code is not exacly opencart module, its just simple script for me to get all discount coupons to database and dont do it one to one ;) – Martin Zigi Ziegler 20 hours ago

closed as not a real question by Quentin, Fabio, shadyyx, hjpotter92, Stony 20 hours ago

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

Try this one:

$co = "SELECT * FROM oc_coupon";
$navrat = mysql_db_query($database, $co, $spojeni);
$i = 0;

while ($row = mysql_fetch_row($navrat)) 
{
    $pole2[]= $row['coupon_id']; // if you have coupon id field like this

    $cnt = count($pole1);

    while($i < $cnt):
         mysql_query("INSERT INTO oc_coupon_product (coupon_id, product_id)  VALUES('".(int)$coupon_id.",'".mysql_real_escape_string($pole1[$i])."')",$spojeni);
         $i++;
    endwhile;
}
share|improve this answer
Just tryed but same problem like before. Nothing happend – Martin Zigi Ziegler 21 hours ago
can you share the code for "$pole1" – skparwal 20 hours ago
here is the whole code pastebin.com/E7tYW7qs code for $pole1 starts on line 22 – Martin Zigi Ziegler 20 hours ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.