Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: iterating rows

  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts

    iterating rows

    OK, this has to be easy. I am just missing something.
    I am trying to pass in a var to a php page. run a (mysql) query and pass back.

    getting one line of data I have done before. But this I will need to return multiple rows of data. So

    PHP Code:
    $depot=$_GET['depot'];
     
    $query "SELECT store, address, city, state, zip FROM store WHERE depot='$depot'";
                 
    //mysql_fetch_assoc
      
    $result1 mysql_query($query) or die ('Invalid Query - Cannot retrieve equipment Type' .mysql_error() ); 
    now I am trying to iterate and collect the data
    Neither of these seem to work for me.

    PHP Code:
    while ($row mysql_fetch_assoc($result1)) {
        
    $fullAddress $fullAddress $row['store'];

    or

    PHP Code:
    while ($row $result1->fetch_row()) {
            
    $fullAddress $row[0] . $row[1];
        } 


    thanks for any help

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    First thing I'll mention: validate and sanitize! People could put anything into $_GET's, so make sure what goes into your query is only what you expect!

    Next, what doesn't work about the first one? That is the right code technique... does it not display what you want, or does it not display anything?

  • Users who have thanked Keleth for this post:

    gregd101 (06-18-2012)

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    If you want to "pass it bacK" I'll guess that you're doing this in a function. Store what was found in an array and send it back (the array). Then do what you need to with it.

    PHP Code:
    while ($row mysql_fetch_assoc($result1)) {
        
    $fullAddress[] = $row['store'];
    }
    return 
    $fullAddress
    If you're just trying to display each of the results use:

    PHP Code:
    while ($row mysql_fetch_assoc($result1)) {
        echo 
    $row['store'];

    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    gregd101 (06-18-2012)

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I am trying to pull each store and full address (address + city + state + zip)
    eventually I would like to pass back to my original page from this php page by

    PHP Code:

    $fulldata 
    $fulldata '<item><store>'.$store.'</store><fulladdress>'.$fulladdress.'</fulladdress></document><item>' 

    PHP Code:

     $return_value = '<?xml version="1.0" standalone="yes"?><document>'.$fulldata.'</document>';

  • #5
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts
    When I throw them together trying to just pass back any data,
    It seems like I am getting

    <b>Parse error</b>: syntax error, unexpected T_STRING in <b>getDepotStore.php</b>


    PHP Code:

    while ($row = mysql_fetch_assoc($result1)) {
        $fulldata = $fulldata . $row['store'];
    }

    $return_value = '<?xml version="1.0" standalone="yes"?><document><stores>'.$fulldata.'</stores></document>';

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    It doesn't tell you what line the error is on?

  • Users who have thanked Keleth for this post:

    gregd101 (06-18-2012)

  • #7
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts
    the error was on a line after the end of the code. which was strange.
    But with some tweaking I go it to work.

    thanks

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Can you show us what you fixed?

  • #9
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts
    my data had a & in it so I removed it with a str_replace. Not sure why the error was after the last line of code. Maybe the data added some lines. Since this was a pass back page, I am not sure how to grab the source before the return back. But it seems like the HttpRequest has a problem with &.
    thanks all


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •