SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can you help me with my syntax?

    Consider this code from a dynamic table:

    WHERE counties.SCode = 'wy' ORDER by NameS";

    "wy" = Wyoming. If I replace wy with ny, the table displays data for New York.

    I realized that I could put the entire table in an include page and just use an echo function to rotate postal codes. But I hit a snag.

    I put the table in an include, then replaced "wy" with an echo function - but I get an error message. Below are some of the variations I've tried, all without success:

    PHP Code:
    WHERE counties.SCode = '<?php echo "$mycode?>' ORDER by NameS";
    WHERE counties.SCode = "<?php echo "$mycode?>" ORDER by NameS";
    WHERE counties.SCode = '' . "$mycode" . '' ORDER by NameS";
    WHERE counties.SCode = ' . "$mycode" . ' ORDER by NameS";
    WHERE counties.SCode = '/' . "$mycode" . '/' ORDER by NameS";
    I posted all the code from both the main page and the included table below, leaving lots of white space around the problem areas. Any tips?

    Thanks.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en">
    <head>
    <?php
    $seg 
    '../../../';
    $myname 'Wyoming Counties';
    $mystate 'Wyoming    ';
    $mycode 'wy';
    // unique break
    $nick 'The Roots of Democracy';
    $mynat 'United States';
    $mycont 'North America';
    $mysec 'U.S. Counties';
    $mytopic 'Government';
    // $my break
    $state '' $mycode '';
    $nat 'us';
    $cont 'na';
    $sec 'topics/gov/counties';
    $topic 'gov';
    include (
    $seg."a1/inc/headtopics.php")
    ?>
    </head>
    <body class="topic" id="<?php echo "$mytopic?>">
    <div class="body2" id="<?php echo "$mycode?>">
      <div class="body3">
        <?php include ($seg."a1/inc/toptopics.php"); ?>



    <?php include ($seg."a1/inc/tablecounties.php"); ?>



        <div class="footnotes"><strong>Footnotes...</strong><br />
    &nbsp;</div>
        <div class="return">Return to: <a href="index.php">U.S. Counties</a> | <a href="<?php echo "$seg?>us/<?php echo "$mycode?>/index.php"><?php echo "$mystate?></a></div>
        <?php include ($seg."a1/inc/footer.php"); ?>
      </div>
    </div>
    <?php include ($seg."a1/inc/reftools.php"); ?>
    </body>
    </html>
    And here's the included page, which hosts the dynamic table, again with some white space around the offending code...

    PHP Code:
    <?php
    $todayDate 
    date("m-d-Y");
    ?>
        <table class="sortable" id="tabcounties" cellspacing="0">
          <thead>
            <tr class="rowheader">
              <th class="name">Name</th>
              <th class="name">Seat</th>
              <th class="name">Area</th>
              <th class="name">PD</th>
              <th class="name">Pop</th>
              <th class="name">1_Race</th>
              <th class="name">2+</th>
              <th class="name">Native</th>
              <th class="name">White</th>
              <th class="name">Black</th>
              <th class="name">Asian</th>
              <th class="name">PI</th>
              <th class="name">Other</th>
              <th class="name">Hisp</th>
            </tr>
          </thead>
          <tbody>
            <?php require_once('' $seg 'Connections/World.php');
    // probably something to initialise mysql connection

    mysql_select_db($database_World$World);
    // select right database

    $query_Counties "SELECT counties.NameC, counties.Seat, counties.Area_MI, counties.Pop_2000,
      counties.Pop_MI, counties.Pop_2000, counties.Race1, counties.Race2, counties.Amerindian,
      counties.White, counties.Black, counties.Asian, counties.Pacific_Island, counties.Some_Other_Race,
      counties.Hispanic from counties inner join states




    on counties.SCode = states.SCode WHERE counties.SCode = '<?php echo




    "
    $mycode" ?>' ORDER by NameS";

    $Counties mysql_query($query_Counties$World) or
    die(
    mysql_error());
    // send it to mysql (step 2.)

    while ($row_Counties mysql_fetch_assoc($Counties) ) {
    // loop throught the resulting record set and display each row (step 4.)

      
    echo "<tr>\n";

      echo 
    "<td class=\"name\">";
      echo 
    $row_Counties['NameC'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"seat\">";
      echo 
    $row_Counties['Seat'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"area\">";
      echo 
    $row_Counties['Area_MI'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"density\">";
      echo 
    $row_Counties['Pop_MI'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"pop\">";
      echo 
    $row_Counties['Pop_2000'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"race\">";
      echo 
    $row_Counties['Race1'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"race\">";
      echo 
    $row_Counties['Race2'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"native\">";
      echo 
    $row_Counties['Amerindian'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"white\">";
      echo 
    $row_Counties['White'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"black\">";
      echo 
    $row_Counties['Black'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"asian\">";
      echo 
    $row_Counties['Asian'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"pi\">";
      echo 
    $row_Counties['Pacific_Island'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"other\">";
      echo 
    $row_Counties['Some_Other_Race'];
      echo 
    "</td>\n";

      echo 
    "<td class=\"hisp\">";
      echo 
    $row_Counties['Hispanic'];
      echo 
    "</td>\n";

    // If your query results in other columns then you'll obviously need to
    // change these lines to reflect the names and number of columns!

      
    echo "</tr>\n";
    }
    ?>
          </tbody>
        </table>

  2. #2
    SitePoint Zealot soart's Avatar
    Join Date
    Nov 2003
    Location
    Norwich UK
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why r u echoing when already within a php call

    PHP Code:
    $query_Counties "SELECT counties.NameC, counties.Seat, counties.Area_MI, counties.Pop_2000, 
    counties.Pop_MI, counties.Pop_2000, counties.Race1, counties.Race2, counties.Amerindian, 
    counties.White, counties.Black, counties.Asian, counties.Pacific_Island, counties.Some_Other_Race, 
    counties.Hispanic from counties inner join states 
    on counties.SCode = states.SCode WHERE counties.SCode = '
    $mycode' ORDER by NameS"
    not that im any kind of expert, just a thought, didnt produce a syntax error when i tried it

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Stekene, Belgium
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Echo sends the output to the output buffer. You can redirect that buffer to a String when you call ob_start. But in your example it is not necessary to use echo. Just use the concat . operator to build your SQL statement.
    Good artists copy, great artists steal (Picasso)


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
  •