SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 38 of 38
  1. #26
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone give me any more help please?

    I really can't see how to sort this out.

  2. #27
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use strlen() and optionally trim() to test the length of a string. If the length is zero, its empty, nothing there. Because it is pointless to output a blank string, you can have your code only output if its not blank.

  3. #28
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right ok I understand that but what is getting to me is that the part of my code where I can use strlen() is part of the part for the rows content so the row has already been started and I basically wnat no part of the row to be outputted if the field is empty.

    Thats what I am trying to explain.

    Thanks

    Regards,
    Neil

  4. #29
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please someone. I really am desperate to get this sorted. I know I'm thick but I really can't find a way to do it myself without the <tr><th><h2>Cost</h2></th><td> part being repeated.

  5. #30
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is your updated code?
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  6. #31
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Here is the latest block of code:

    PHP Code:
        <?php
            $sql 
    "SELECT atm_areas.area_name
                    FROM atm_areas, atm_rides, atm_area_ride
                    WHERE atm_rides.ride_id = "
    .${$method}[$item.'_id']."
                    AND atm_rides.ride_id = atm_area_ride.ride_id
                    AND atm_areas.area_id = atm_area_ride.area_id"
    ;
            
    $result mysql_query($sql);
            if (
    mysql_num_rows($result) >= 1) {
        
    ?>
                <tr>
                    <th>
                        <h2>
                            Location
                        </h2>
                    </th>
                    <td>
                        <?php
                            
    while ($getstatdata mysql_fetch_array($result)) {
                                echo 
    sprintf('%s<br />'$getstatdata['area_name']);
                            }
                        
    ?>
                    </td>
                </tr>
        <?php
            
    } else {
                echo 
    null;
            }
        
    ?>

  7. #32
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see any <tr><th><h2>Cost</h2></th><td> in your updated code...what do you mean in Post #29?:

    Please someone. I really am desperate to get this sorted. I know I'm thick but I really can't find a way to do it myself without the <tr><th><h2>Cost</h2></th><td> part being repeated.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  8. #33
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rctneil View Post
    Here is the latest block of code:

    <?php
    $sql = "SELECT atm_areas.area_name
    FROM atm_areas, atm_rides, atm_area_ride
    WHERE atm_rides.ride_id = ".${$method}[$item.'_id']."
    AND atm_rides.ride_id = atm_area_ride.ride_id
    AND atm_areas.area_id = atm_area_ride.area_id";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) >= 1) {
    ?>
    <tr>
    <th>
    <h2>
    Location
    </h2>
    </th>
    <td>

    <?php
    while ($getstatdata = mysql_fetch_array($result)) {
    echo sprintf('&#37;s<br />', $getstatdata['area_name']);
    }
    ?>
    </td>
    </tr>
    <?php
    } else {
    echo null;
    }
    ?>
    The part you are querying is in bold in the segment above

  9. #34
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah - you mentioned a cost column which caused confusion.

    What do you mean? - it isn't repeated by the look of that code
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #35
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I only mentioned cost as that was the row I was working on at the time but I changed. Will be the same code but for different stats throughout the table.

    What I mean by it will repeat is that I cannot get the code to check if a table field is empty after checking if 1 or more rows ahve been returned without the segment of code I previously highlighted getting repeated, ie: creating more starts to rows which would be syntactically incorrect.

  11. #36
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    First of all, use explicit inner joins, not implicit cross joins. Also, update your query to only return fields that have length.
    I've done it for you, and indented the code. Please, for your own sake, start tab indenting your code - otherwise you will get a headache looking for errors.
    PHP Code:
    <?php
    $sql 
    "SELECT atm_areas.area_name FROM atm_areas
    INNER JOIN atm_area_ride ON atm_area_ride.area_id = atm_areas.area_id
    INNER JOIN atm_rides ON atm_rides.ride_id = atm_area_ride.ride_id
    WHERE
        atm_rides.ride_id = "
    .${$method}[$item.'_id']."
        AND LENGTH(area_name) > 0
    "
    ;
    $result mysql_query($sql);
    if (
    mysql_num_rows($result) >= 1) {
        echo <<<ROW
        <tr>
            <th>
                <h2>Location</h2>
            </th>
            <td>
    ROW;
        while (
    $getstatdata mysql_fetch_array($result)) {
            echo 
    sprintf("                %s<br />\n"$getstatdata['area_name']);
        }
    echo <<<ENDROW
            </td>
        </tr>
    ENDROW;
    }
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  12. #37
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,890
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right, I will check through that a bit later when I have a bit more time. Also, I do indent my code but when I paste it on sitepoint it doesn't always display correctly. Can you explain what the parts in green do?

  13. #38
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's HereDoc

    It's basically a string block, preferred over quotes when outputting HTML.

    This is because strict XHTML (which we should all be using) requires attributes to be quoted with double quotes. This means that to insert variables into a HTML string with quotes, you have to use:
    PHP Code:
    <?php
    $myValue 
    'Hello World';
    echo 
    '<p class="mymessage">'.$myValue.'</p>';
    //or
    echo "<p class=\"mymessage\">{$myValue}</p>";
    Both are messy - what you want is a mixture of the two, where you can output double quotes without slashes and a variable (which you can't output in a single quoted string).

    Heredoc to the rescue:
    PHP Code:
    <?php
    $myValue 
    'Hello World';
    echo <<<MESSAGE
        <p class="mymessage">{$myValue}</p>
    MESSAGE;
    As a rule, the end of a heredoc (in this case MESSAGE) needs to be the first and last thing on the line.

    In fact, I'll ask forum support if they can modify the PHP output to cater for HereDoc - it can look erronious with the current syntax highlighting, which doesn't support heredoc.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

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