emma57573 Posted July 3, 2008 Share Posted July 3, 2008 Im trying to ask if a mysql result that matches comes up more than once in the same session / for loop. I was thinking something like this $uid = $sub["uid"]; $uid > 2) But that doesnt make sence at all as its looking at the just the result. I thought about counting an array but that wont work because I want to look at the results in the array and if they match I want to count them. The results are in a for loop inside a session. Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/ Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Do you not want duplicate results? You can use SELECT DISTINCT in your query instead... o-O Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580681 Share on other sites More sharing options...
emma57573 Posted July 3, 2008 Author Share Posted July 3, 2008 I do want multiple results but at the end of the results I want to ask: 'if 'said' variable has come up more than once and the result matches then do something' Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580683 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 I don't understand the "if the result matches" part. Explain a little more please. Sorry, it's 3 AM. =X I'm talking to my girlfriend so I can't really go to sleep, so I'm on here too. xD Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580684 Share on other sites More sharing options...
emma57573 Posted July 3, 2008 Author Share Posted July 3, 2008 Sorry Im terrible at explaining myself Its in the '///////////////Im stuck with this postage bit AGAIN:' bit. Im trying to ask if the user is from overseas AND the store offers postage world wide then offer worldwide shipping: THEN if the user has ordered more than one item from the same store then offer a combine shipping price on the second and addition items $sub["uid"] holds the stores id. This is not the page where the script is held. The script is for the final checkout but it might give you a good idea of what im trying to do: http://www.misi.me.uk/viewcart.php Sorry for being such a novice I do try and look these things up but I can never find what I need! foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM freetplclassified_products WHERE id = '.$id; $result = $db->query($sql); $rst = $result->fetch(); $rs_t=mysql_fetch_array(mysql_query("select * from freetplclassified_members where id=".$rst["uid"])); $freetplq_img=mysql_fetch_array(mysql_query("select * from freetplclassified_images where pid=".$rst["id"])); $subtotal = 0.00; extract($rst); $output[] = '<table width="90%" cellpadding="5" class="onepxtable" align="center"">'; $output[] = '<tr>'; $output[] = '<td colspan="3"><h2>Your <a href="http://www.misi.me.uk/store_info.php?id='.$rst["uid"].'">'.$rs_t["username"].' Order</a></h2></td>'; $output[] = '</tr>'; $output[] = '<tr>'; $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'"><img src="http://www.misi.me.uk/uploadedimages/'.$freetplq_img["url"].'" width="75" height="75" border="0" class="onepxtable"></a></td>'; $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'">'.$product_name.'<br><br></td>'; $output[] = '<td align="right">£'.$buy_price.'<br><br>Quantity: '.$qty.''; /// Postage details if (($rst["worldwide"]=="yes")&&($country!="UK")){ $output[] = '<br><br>Overseas Postage: '.$worldwide_shipping.''; } ///////////////Im stuck with this postage bit AGAIN: if (($rst["worldwide"]=="yes")&&($country!="UK")&&($sub["uid"] > 2) ){ $output[] = '<br><br>Combined Overseas Postage: '.$worldwide_combine_shipping.''; } ///////////////Im stuck with this postage bit AGAIN: $output[] = '<br><br>Postage: '.$shipping_price.'</td></tr>'; $subtotal += ($buy_price * $qty + $shipping_price); $output[] = '<tr><td colspan="3" align="right"><class="smlgrey">Sub total</class> £'.number_format($subtotal.$cents,2,'.','').'</td></tr>'; $total += $buy_price * $qty + $shipping_price; $output[] = '</tr>'; $output[] = '</table><br><br>'; } $output[] = '</table>'; $output[] = '<p>Total: <strong>£'.number_format($total.$sents,2,'.','').'</strong> <class="smlgrey" Excludes Postage</class></p>'; $output[] = '<p>Please note Postage will be calculated on checkout</p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580685 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Where do you store the items that they bought from a store? The database? Just do a SELECT COUNT(*) query on it with the proper username (or ID) and store id to check, then use that result. Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580688 Share on other sites More sharing options...
emma57573 Posted July 3, 2008 Author Share Posted July 3, 2008 ok thanks I will give that a go, yes they are all in a database Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580704 Share on other sites More sharing options...
emma57573 Posted July 3, 2008 Author Share Posted July 3, 2008 OK The data wont be inserted to the database until the user hits confirm on this page although all the data comes from a database and is placced into a session but you gave me a big clue so I tried this feeling sure it would work: $countuid = $rst["uid"]; /// Postage details $worldwide = ($rst["worldwide"]=="yes")&&($country!="UK"); $sub = 'SELECT * FROM '.$_SESSION["cart"].' WHERE uid=$countuid ORDER BY COUNT(*)'; if ($worldwide&&($sub > 1)){ $output[] = '<br><br>Combined Overseas Postage: '.$worldwide_combine_shipping.''; } Im not sure why that wouldnt work: Im not getting any errors its just not working if I type in $sub = 1 insead then it works but uses combined postage for everything so its obviously not counting properly :-\ Link to comment https://forums.phpfreaks.com/topic/113040-sorry-me-again/#findComment-580729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.