Jump to content

l!m!t

Members
  • Posts

    50
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

l!m!t's Achievements

Member

Member (2/5)

0

Reputation

  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!
×
×
  • 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.