Jump to content

perky416

Members
  • Posts

    177
  • Joined

  • Last visited

About perky416

  • Birthday 02/14/1988

Profile Information

  • Gender
    Male
  • Location
    West Midlands

perky416's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hi everyone, Sorry i've just found my problem, i had the $i++ out side of the while loop.
  2. Hi guys, I have a html table that contains rows of data, and each row has a check box next to it so the user can delete each row if the box is ticked I am using the following code to display a warning message before the entry is actually deleted, however lets say I have 10 rows of data, and only tick 1 check box, the same warning message is displayed 10 times instead of just the 1. if($_POST['submit']){ $i = 0; while($row = mysql_fetch_assoc($query)){ if ($_POST['check'][$i]){ echo "You are about to delete " . $_POST['check'][$i]; } } $i++; } Does anybody have any ideas as to how I only get the message to display once for each row checked, rather than once for all rows. Many thanks
  3. Hi guys, Thanks but i managed to solve it shortly after posting. Like a muppet i forgot i was actually saving the URL of the image in the database, i simply recalled the url as the image SRC. Thanks.
  4. Hi everyone, Sorry not sure if this is a php or html problem. Im using php and a html form to upload images to my site, i have made it so that jpg, jpeg, gif and png images can be uploaded. The problem im having is displaying the image. <img src="images/<?php echo $name ?>.jpg" /> That works fine if a jpg was uploaded, but what if a png or a gif was uploaded? The $name is going to be unique, there will not be more than one image with the same name, so what do i have to do to display the image regardless of what the extension is? Thanks
  5. Hi mjdamato, I completely agree with you, I would love to keep my php and html totally separate! I have a right game trying to interpret it all. The only problem is i dont know how. For example how would I go about displaying a form text box for each row in a database table without using php within the html? Thanks
  6. Hi requinix, Yes I tried it lol. Its as if its not reading the query. To get it to work I actually have to place a 2nd query exactly the same within the same php tags as the while query. <?php $query = mysql_query("SELECT whatever FROM table1 WHERE id='1'"); while (mysql_fetch_assoc($query){ ?> Thanks
  7. Hi everyone, Is it possible to use a query in multiple sections of php that are separated by html? If you look at the example below, You can see my defined query at the top of the page, but I also want to use the same query for the while loop that has been put within the html to repeat the textbox. I know I could get around this by putting the html within php however I wanted to keep my html and php separate if possible. <?php $query = mysql_query("SELECT whatever FROM table1 WHERE id='1'"); // some php here ?> <html> <form> <?php while (mysql_fetch_assoc($query){ ?> <input type="text" /> <?php } ?> </form> </html> Thanks
  8. Hi everyone, In case anybody else comes across this post looking for the same thing, here is my solution. It only uses 1 query to update the database and after tests updating 2 columns with 100 rows each, it was found to be about 4 times faster than using a query within a while loop. $i = 0; while($row = mysql_fetch_assoc($query)){ $product_string .= " WHEN domain='" . $_POST['checkbox_value'][$i] . "' THEN '" . $_POST['product'][$i] . "'"; $price_string .= " WHEN domain='" . $_POST['checkbox_value'][$i] . "' THEN '" . $_POST['price'][$i] . "'"; $i++; } mysql_query("UPDATE table1 SET column1 = CASE" . $product_string . " ELSE column1 END, column2 = CASE" . $price_string . " ELSE column2 END"); I hope it helps.
  9. The code im using is similar to the following: Query within a while loop: while($row = mysql_fetch_assoc($query)){ mysql_query("UPDATE products SET price='$_POST['price'][$i] WHERE product='$_POST['checkbox_value']'"); $i++; } single query using case: while($row = mysql_fetch_assoc($query)){ $string .= "WHEN product='" . $_POST['checkbox_value'][$i] . "' THEN ' ". $_POST['price'][$i] . "'"; $i++; } mysql_query("UPDATE products SET price = CASE $string ELSE price END");
  10. Hi mate. Even though with a while loop a new query is executed for each row? but with case only one query is executed for all rows? A while is still more efficient and faster? Just trying to understand. Thanks mate.
  11. Hi everyone, Please could somebody give me their views on which is a more efficient and faster way to update multiple rows of a database with different values? Using a query within a while loop or using a query with a case? Thanks
  12. Hi everyone How would i put the values of a foreach into a single string? Lets say I have 2 $_POST['test'] values. In the example below the first echo will display something like "This is a TestThis is a Test", and the 2nd echo will display something like "Hello This is a Test". foreach ($_POST['test'] as $test){ $string = "This is a '" . $test . "'"; echo $string; } echo "Hello $string"; How would I get the 2nd echo to display something like "Hello This is a TestThis is a Test" for use outside of the foreach? Thanks
  13. Hi djlee, I was using the checkbox value as the unique key. Iv tried using your example however for the life of my I cant get it to work. Im only working with 2 products atm, it is inserting 2 new rows each time i submit the form, and it is updating the value in all of the previous rows apart from the original 2 that i am trying to update. Do you have any idea as to what i could be doing wrong? Thanks
  14. Hi AyKay47 Iv threw together a quick example of the form im using: www.directbullion.co.uk When a user changes the value in the text box, ticks the checkbox and clicks save changes, im trying to update the database using as few a queries as possible. If I use a while loop wouldn't multiple queries be submitted? Thanks
×
×
  • 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.