everything is inserting into one row instead of separate rows

Discussion in 'PHP' started by xbat, Dec 21, 2013.

  1. #1
    I have some code where everything is inserting into one row instead of separate rows. I am not sure what I am missing. Any pointers would greatly be appreciated.

    $p = '';
    
    foreach($html->find('.td.thing) as $price) {
       
        $p.= $price->innertext.'';  
       // $p.= $price->innertext.'td';
    }
    
    
    $q = "INSERT INTO something (`one`, `two`) VALUES ('$a', '$p')";
    PHP:
     
    Solved! View solution.
    xbat, Dec 21, 2013 IP
  2. #2
    The code is horrible, I'm not sure the quotation marks are proper, but anyway, you're ending the loop before the insert, hence, only one insert
     
    PoPSiCLe, Dec 22, 2013 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    I moved the bracket but that didn't seem to work. As for horrible what do you mean by horrible. Thank you for your help so far.
     
    xbat, Dec 23, 2013 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Is that your whole code? Because not only is your query outside the loop, but you're also not actually executing it.
     
    nico_swd, Dec 23, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    What nico said.. and being the query is in a string,you're probably still using the soon to go the way of the dodo that we've been told for eight years to stop using mysql_ functions, right?

    Though you seem to be parsing data out of HTML -- without seeing that data and a whole lot more of your code there's really not a lot we can offer for help.
     
    deathshadow, Dec 24, 2013 IP
  6. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #6
    there she blows... \/ I have updated it a little. thank you for the help so far. :)

    
    
    $p = '';
    
    foreach($html->find('.td.thing) as $price) {
    
       $p.= $price->innertext.'';
    $q = "INSERT INTO something (`two`) VALUES ('$p')";
    
    $b= mysqli_query ($dbconnect, $q) or die ("Update query failed : " . mysql_error());
    }
    
    
    
    
    PHP:

    Actually I just found one error I had a extra ; and I had to remove the dot in front of the p and works like lucky charms magically php.



    thank you for everyones help.. It was just no loop like what they said above. I will give you best answer.
     
    Last edited: Dec 27, 2013
    xbat, Dec 27, 2013 IP