mbait Posted March 1, 2006 Share Posted March 1, 2006 Hello. I'm sort of new to PHP, but I'm in need of assistance with a WHILE loop statement.This is what I'm trying to do.Visitors who are interested in downloading a digital product from me, must first create a member account. A product link for that particular download is automatically placed in their Download Management area once the new account is created.I'm wanting the PHP script to also place product links for other digital products I label as "Free" in their Download Management area too.Here's what I have.$result = mysql_query("SELECT * FROM products WHERE itemStatus='free' ORDER BY 'added' DESC") or DIE("Could not Select from products");while ($data = mysql_fetch_assoc($result)) {$itemId = $data['itemId'];$itemName = $data['itemName'];$result1 = mysql_query("SELECT * FROM filename WHERE itemId='$itemId' LIMIT 1") or DIE(mysql_error());$data1 = mysql_fetch_assoc($result1); if (mysql_num_rows($result1) > 0) { $itemId = $data1['itemId']; $fileId = $data1['fileId']; $resell = $data1['resell']; if ($resell == 'NO') { $type = 0; } else { $type = 1; }} $result2 = mysql_query("INSERT INTO downloads SET custId='$custId', orders='$orders', itemId='$itemId', fileId='$fileId', prod_fileName='$itemName', download_maxdays='$download_maxdays', download_maxcount='$download_maxcount', datedl='$datedl', ipaddr='$ipaddr', type='$type'") or DIE(mysql_error()); $downId = mysql_insert_id();}The above does work, but there is one problem. If the digital product they initially created their account for is "Free", the above While statement places a second entry for it in their Download Management. Is there anyway of saying...If product X already exists for the Customer in the Downloads Table, then skip this row, returning to the top of the While loop looking for any other "Free" files to add.Can someone help? Hope I explained this well enough. Quote Link to comment Share on other sites More sharing options...
zq29 Posted March 1, 2006 Share Posted March 1, 2006 If the original download they selected is passed to this script, you could alter your first query to something like this:[code]$result = mysql_query("SELECT * FROM products WHERE itemStatus='free' AND `itemId` != '$_POST[itemId]' ORDER BY 'added' DESC") or DIE("Could not Select from products");[/code] Quote Link to comment Share on other sites More sharing options...
mbait Posted March 2, 2006 Author Share Posted March 2, 2006 Hello. Actually after sleeping on it last night, I did come up with the very solution your suggesting.I actually assigned a unique varName to the original product link being inserted and altered the line above the While statement to say:$result = mysql_query("SELECT * FROM products WHERE itemStatus = 'free' and itemID != '$prodId' ORDER BY 'added' DESC") or DIE("Could not Select from Free products");The above works and hopefully anyone else coming across a similar situation can use this to their advantage. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.