Jump to content

l!m!t

Members
  • Posts

    50
  • Joined

  • Last visited

    Never

Everything posted by l!m!t

  1. I have a list of items I am running through a PHP loop. The columns are (car_name, car category) . I want to retrieve all the car names and sort them under their defined category. (example: Category 1 Ford 1 Ford 2 Ford 3 Category 2 mazda 1 mazda 2 mazda 3 I tried - (select car_name from my_table group by category). However it seems to also group all the cars into one result. Basically I only want the category to show once and each car within that category to show below. Any idea what I am doing wrong? I tried using DISTINCT as well..
  2. Hi, Thanks for the reply. Well, I know the query works I am stuck on how to insert values from both arrays in one loop. Basically I am trying to save time by using PHP to insert the array values from a for loop. I can get it to insert a single set of array values, however its the second array doesn't input correctly. I somehow have to combine both arrays into one and then have a way to output them as individual values based on their array name. I am not sure if this is even possible. I guess something like this .. $cars = array('ford', 'toyota', 'bmw'); $places =arrray('Orlando','California','Texas'); foreach ($combined_array as $values){ $car=$cars['car']['value']; $place=$places['place']['value']; $query = "INSERT INTO vehicles (cars, places) VALUES ('$car', '$place')"; } Any ideas?
  3. Hello, I have been at this for awhile now and cant seem to figure it out. I have 2 separate arrays like shown below and I am trying to insert each value into my database using one update query. I have tried a for loop inside each array, but only one column populates. I have tried breaking the values outside their for loop, etc, etc. Does anyone know a way this can be done? //Cars $cars = array('ford', 'toyota', 'bmw'); //Places $places =arrray('Orlando','California','Texas'); foreach ($cars as $car){ foreach ($places as $place){ $place .=$place; } mysql_query("INSERT INTO vehicles (cars, places) VALUES ('" . $car. "', '" . $place . "'')"); }
  4. Hey RussellReal, Thanks for the solution! Works exactly as needed. Much appreciated.
  5. I have a question - I have a table with 3 rows (id, class, value) Is it possible to get the results of two rows without doing two separate SQL query's. For example - right now I am doing select value from tablename where class='total' and id=$id I want to be able to also get the value where class='coupon' basically I want to combine the following into 1 statement as if they were two queries.. select value from tablename where class='total' and id=$id select value from tablename where class='coupon' and id=$id is that even possible .. am I making sense?
  6. Thanks travo1992! That worked, much appreciated!
  7. Hello, I want to pull some fields into an array from a while loop, so I can later use them in a for loop. I am confused how to get the array from the while into the correct formatting. I have a mySQL while that grabs the data while ($postage =db_fetch_array($postage_query)){ $i++; $custname =$postage['delivery_name'] . '&'; $custaddress = $postage['delivery_street_address']; $buildArray = array("name_" . $i => $custname, "full_address_" . $i => $custaddress); $i; } ^ For obvious reasons the buildArray keeps looping the ""array"" how can I have the array only loop once like below? If I break it out it then fails to count $i... I want the formatting something like the below example. / Array ( [name_1] => John Doe => [name_2] => John Doe 2 => [full_address_1] => 1234 test street => [full_address_2] => 1234 test street 2; ) */ I then want to be able to loop in into a for each foreach ($buildArray as $key => $val){ echo $key . '' . $val; } Any help would be great I am still learning PHP arrays..
  8. God.. I must be tired. I was set on a single digit like "10"... I didn't see the result was the actual total. Thanks again for your time.
  9. Hi, Thanks for the help! Is there anyway I can narrow down to only the fist number? The example below kicks out 505O, but I only need one 50 $value=5000; echo $value * 1.01; //result 5050
  10. I have a form which posts a dollar amount I am trying to figure out how I can add $10 for every $1000 ? so it should do the following $1000 + 10 $2000 + 20 $3000 + 30 How would I go about doing this? The only thing I can think of would be a for loop and to some how break up the values into thousands.. - I am new to PHP so don't fully know all the functions. Any suggestion would be great.
  11. I figured it out - I just used the php explode function to split the dash and then put into two separate arrays explode('-',$foobar ,2); Maybe it will help somebody else.
  12. Hello, I am trying to create a table rate discount function, which is based on quantity - Right now I have it so it discounts using the following method - 20:10, 50:20 which comes out to 20 items = 10% off , 50 items = 20% off . I want to re-write it so I can define the qty discount like ( 20 - 50:10, 50-100:20 ) which comes out to - 20 through 50 items = 10% off , 50 - 100 items = 20% off. ) I have been at it for hours, I figure perhaps somebody can give some input on this. This is acutally a function which is looped, but I have hard coded the values for the demo. Any help would be appreciated. My snippet is below. $products_price='5.99'; $qty_table_rate= '20:10, 50:20'; $qd_qty='10'; $qty_table_cost = split("[:,]", '$qty_table_rate); $size = sizeof($qty_table_cost); for ($i = 0, $n = $size; $i < $n; $i += 2) { if ($qd_qty <= $qty_table_cost[$i]) { $qty_discount = $qty_table_cost[$i + 1]; $qd_price = $products_price * $qty_discount / 100; break; } }
  13. I am a PHP newbie, hoping someone can give some insight on an approach for the following. I would like to be able to $_post variables from an HTML form into predefined areas of an HTML template and then save it. Is fopen() and preg_match put into a loop the best approach for this? For example if my html template which I want to post to has the following text. " I am {{sample}} text replace {{me}}". I would want to replace the variables "sample" and "me". The form "field names would be the values in the template (eg: " sample" and "me" and the script would search for values contained in the brackets. preg_match("/{{[A-z0-9_]*}}/i", $vars, $locate); Does this logic make any sense is there another way to do this aside for preg?
  14. Hello, I cant seem to figure out how I can list duplicate results from the same row. For example I want to list all the duplicate "model_numbers" within my "model_number" row. I found examples how to count them using "group by", but I want to list only the duplicates individually not count them. Any example how to do this would be great - my basic query minus the "while loop". select model_number from mytable order by model_number ASC I only want to retrieve duplicate model numbers and then list them. Any help would be great.
  15. Cool this worked! .. Yeah I would have used mySQL distinct, but it would result in multiple rows for each keyword, multiple inputs etc. Thanks a ton for your time and for the help!
  16. I checked for spaces typos etc..I too thought array_unique would work. I think the problem is that the function explodes all commas, but only for that individual mySQL result. When its being looped from each row, there is no way for it know all duplicates as a total. So rows that have duplicate names are being ignored. I think I have to somehow pull all the sql results into a giant foreach and then use array unique to sort those results.. I have no clue how to do this, but will try to explain. any thoughts on this would be great. Something like this - while($tag_result = db_fetch_array($tag_query)){ $result.=array($tag_result['my_tag']); } foreach($result as $key => $value){ echo explodeTagCloud($value); }
  17. Hi haku, Thanks for the reply.. I added $tags_result = array_unique($tags_result); to the function, but its still bringing up duplicates. This function goes into a mySQL while loop (eg ) .. while($tag_result = db_fetch_array($tag_query)){ echo explodeTagCloud($tag_result['my_tag']); Any suggestions would be great.
  18. I have a function to build a generic tag cloud..my source pulls from a database where the values are separated by commas. I then have a function to explode each commas into a link, which works fine. Is there anyway to get it so my function only returns unique values?.. Right now its returning duplicates .. I tried implementing array_unique() , but had no luck.. I am still learning. I cant do this from the database as each result is separated by a command as opposed to separate table. function explodeTagCloud($tags) { $build_tags=$tags; $tags_result = explode(",",$build_tags); foreach($tags_result as $key => $value){ echo ' <a rel="'.rand(1, 10).'" href="'.tep_href_link(VIDEO_SEARCH.'?tag='.$value.'','').'">' .$value. '</a> '; } }
  19. Keith, Thank you very much for your time!! Worked perfectly.. I would have never figured it out. Learn something new everyday. Thanks again!
  20. Hi - I have an SQL query I am trying to build, but after hours I am just lost on how to do this. I will try and explain my scenario and also my code. I have 3 tables I want to pull data from to build a pull down menu, in order to do this I have to use joins. One of the tables contains ID's for the menu which I don't want pulled as they are already "used". I cant figure out the SQL query to ignore these ID's. I have tried ! <> NOT EQUAL and even PHP if else, no luck. I am trying to avoid two Query's not sure if its even possible to do this in one query. The table ID's I want it to ignore are in "TABLE_USED" tu.vmobile_id I have tried v.vmobiles_id != tu.vmobile_id, but doesnt seem to work. Any help or suggestion would be great. $vmobile_pulldown_new = tep_db_query("select v.vmobiles_id, vd.vmobiles_name from " . TABLE_V . " v, " . TABLE_V_DESCRIPTION . " vd, " . TABLE_USED . " vu where v.vmobiles_id = vd.vmobiles_id and v.vmobiles_id != tu.vmobile_id and vd.language_id = '" . (int)$languages_id . "' ORDER BY vd.vmobiles_name"); while ($pulldown_new = tep_db_fetch_array($vmobile_pulldown_new)) { $vmobile_array_insert.='<option '.$selected.' value="'.$pulldown_new['vmobiles_id'].'">'.$pulldown_new['vmobiles_name'].'</option>'; }
  21. Ah ok. Thanks, yeah this is the default action from the callback server, they send these $_REQUEST variables anyway. I think since the Callback is offsite is the reason my session doesn't register the variables. This is why I was using $_GET to processes them. Maybe a simple base_64 will work for my needs I was just hoping for something a little more encrypted. Thanks for the help.
  22. I think I will try a POST method, but wouldn't a post method then require it to be submitted as a form ? It would still make the Variables (values) viewable by source or am I wrong?
  23. Hello everyone, I am stuck on something hopefully someone can provide some quick help. I have an array that I have converted to $_GET vars, since I was unable to register it as a session. I want to encrypt the $url output, base_64 seems to easy to decrypt. I have mcrypt on my server, but am lost on how to decrypt the $_GET vars back into an array. Can anyone provide a simple method to do this or an example, I basally only want to decrypt the encrypted vars and put them back into an array. I am not sure if mcrypt is even a solution. Any exaples or help would be great. This is my code. $comments_admin_array=array( 'Test1' => $_REQUEST['Test1'], 'Test2' => $_REQUEST['Test2'], 'Test3' => $_REQUEST['Test3']); $url = ""; foreach($comments_admin_array as $key => $value){ if($url != ""){ $url .= "&"; } $url .= $key . "=" . $value; } ?> http://myurl.com?qd=<?=$url?> // want to encrypt $url Thanks.
  24. Ok will give it a try. Thanks for help.
  25. Wow thanks again for your help. Is it possible to MD5 or encrypt the $url which is finally outputted? I would prefer the variables not be publicly seen (ie viewing source etc)
×
×
  • 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.