Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing student accomodation on a seperate webpage 1

Status
Not open for further replies.

janeybad

IS-IT--Management
Sep 28, 2008
26
0
0
GB
I have a website that shows a load of properites but I was wondering if I could pull just the student properties into one web page.

Every student property has STUDENT LET as the starting text sent from the SQL table.

Any ideas would be greatfully recieved.

Jane XXX




 
Should be straightforward to change the query that gets the data, but you probably need to show us the PHP (including the SQL query) and some sample lines of data.

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
yes you r query will be something along the lines of:
select * from thetable where startingtext = "STUDENT LET".
As johnwm says post some more specifics for more help.
 
Sorry everyone if my first question lacked understanding but I am trying to get to grips with all this and really appreciate the help. Hope this makes sense in relation to the question at the top of the page and thank you all again in advance XXX

Code:
<?php
  // Script to generate the dynamic page content

  // print '<div class="debug">Start of script</div>' . "\n";

  require 'listing.inc';

  function displayNavigation($pageCount, $curPage)
  {
      // Is there more than one page?
    if ($pageCount > 1)
    {
      // Yes - build the page navigation display

      if ($curPage > 1)
      {
        $prevPage = $curPage - 1;

          // Not on page 1:  the "<" should be a link
        print "<a href=\"Properties.php?page={$prevPage}\">&lt;</a>&nbsp;&nbsp;&nbsp;";
      }
      else
      {
          // Page 1:  static "<"
        print '&lt;&nbsp;&nbsp;&nbsp;';
        $curPage = 1;
      }

        // Page links before the current page
      for ($index = 1; $index < $curPage; $index++)
      {
        print "<a href=\"Properties.php?page={$index}\">{$index}</a>&nbsp;&nbsp;";
      }

        // Current page
      print "{$curPage}&nbsp;&nbsp;";

        // Page links following the current page
      for ($index = $curPage + 1; $index <= $pageCount; $index++)
      {
        print "<a href=\"Properties.php?page={$index}\">{$index}</a>&nbsp;&nbsp;";
      }


      $nextPage = $curPage + 1;
      if ($nextPage < $pageCount)
      {
          // Not on last page:  the ">" should be a link
        print "&nbsp;<a href=\"Properties.php?page={$nextPage}\">&gt;</a>";
      }
      else
      {
          // Last page:  static ">"
        print '&nbsp;&gt;';
      }
    }
  }

  function displayProperties($result, $currentProperty, $propertyCount)
  {
    $curRow = 0;
    while (($row = @ mysql_fetch_array($result)) && ($currentProperty < $propertyCount) && ($curRow < 5))
    {
      if (0 != $curRow)
      {
        insertSpacer();
      }


      $imageFile = "photos/tBRANCH_{$row["PropertyID"]}.jpg";

      // print '<div class="debug">Raw row:';
      // print "{$row}";
      // print '</div>' . "\n";

        // Display the data for one entry
      print '  <tr>' . "\n";
      print '    <td height="22" bgcolor="#01009A">&nbsp;</td>' . "\n";
      print '    <td colspan="3" bgcolor="#01009A"><span class="style42">';
      print "{$row["PropertyName"]}";
      print '</span></td>' . "\n";
      print '    <td bgcolor="#01009A"><span class="style26"><span class="style24">&pound;';
      print "{$row["Price"]}";
      print ' PCM</span></span></td>' . "\n";
      print '    <td bgcolor="#01009A"><span class="style26"></span></td>' . "\n";
      print '  </tr>' . "\n";
      print '  <tr>' . "\n";
      print '    <td height="90" bgcolor="#CCCCCC">&nbsp;</td>' . "\n";
      print "\n";
      print '    <td bgcolor="#CCCCCC"><span class="style26"><a href="javascript:;">';
      print "<img src=\"{$imageFile}\"";
      print ' width="170" height="128" border="0" onclick="';
      print "MM_openBrWindow('pop_up.php?propID={$row["PropertyID"]}','Details1','scrollbars=yes,resizable=yes,width=900,height=650')";
      print '" /></a></span></td>' . "\n";
      print '    <td bgcolor="#336699"><span class="style26"><br /></span></td>' . "\n";
      print '    <td bgcolor="#336699"><div align="justify"><span class="style39">';
      print "{$row["ShortDescription"]}";
      print '</span></div></td>' . "\n";
      print '    <td bgcolor="#336699">&nbsp;</td>' . "\n";
      print '  </tr>' . "\n";
      print '  <tr>' . "\n";
      print "\n";
      print '    <td height="19" bgcolor="#01009A">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#01009A"><div align="center" class="style25"><a href="javascript:;" class="style43" onclick="';
      print "MM_openBrWindow('pop_up.php?propID={$row["PropertyID"]}','Details1','scrollbars=yes,resizable=yes,width=845,height=600')";
      print '">Details</a></div></td>' . "\n";
      print '    <td bgcolor="#01009A">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#01009A"><div align="center"></div></td>' . "\n";
      print '    <td bgcolor="#01009A"><span class="style30"><a href="mailto:?subject=';
      print "{$row["PropertyName"]}";
      print '" >Send Enquiry</a> </span></td>' . "\n";
      print '  </tr>' . "\n";

      $currentProperty++;
      $curRow++;
    }

      // Generate any missing table cells
    for ( ; ($curRow < 5) && ($currentProperty >= $propertyCount); $curRow++)
    {
      print '  <tr>' . "\n";
      print '    <td height="22" bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td colspan="2" bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '  </tr>' . "\n";
      print '  <tr>' . "\n";
      print '    <td height="90" bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '  </tr>' . "\n";
      print '  <tr>' . "\n";
      print '    <td height="19" bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '    <td bgcolor="#547CAD">&nbsp;</td>' . "\n";
      print '  </tr>' . "\n";
    }
  }

  function insertSpacer()
  {
    print '  <tr>' . "\n";
    print "\n";
    print '    <td height="19">&nbsp;</td>' . "\n";
    print '    <td>&nbsp;</td>' . "\n";
    print '    <td>&nbsp;</td>' . "\n";
    print '    <td>&nbsp;</td>' . "\n";
    print '    <td>&nbsp;</td>' . "\n";
    print '  <tr>' . "\n";
  }

  if (array_key_exists("page", $_GET))
    $currentPage = $_GET["page"];
  else
    $currentPage = 0;  // Indicates request for first page

  // print '<div class="debug">Page number=' . $currentPage . "\n";

  $query = "SELECT PropertyID, PropertyName, Price, ShortDescription FROM listings";

  // print '<div class="debug">Connecting to server</div>' . "\n";

    // Connect to the server
  if (!($connection = @ mysql_connect($hostName, $userName, $password)))
    die("Cannot connect to server {$hostName}");

  // print '<div class="debug">Opening database</div>' . "\n";

    // Select the database
  if (!(mysql_select_db($databaseName, $connection)))
    showDbError();

  // print '<div class="debug">Issuing query</div>' . "\n";

  if (!($result = @ mysql_query($query, $connection)))
    showDbError();

    // How many properties must be displayed?
  $propertyCount = mysql_num_rows($result);

    // Set current property to index of first property to display (0-based)
  if (0 == $currentPage)
    $currentProperty = 0;
  else
    $currentProperty = ($currentPage - 1) * 5;

    // Number of properties to skip to get to this page
  if ($currentProperty > 4)
    $seekCount = $currentProperty;
  else
    $seekCount = 0;

  $pageCount = ($propertyCount + 4) / 5;

  // print '<div class="debug">Property count=' . "{$propertyCount}  Current property={$currentProperty}  Seek count={$seekCount}</div>\n";

    // Skip properties that belong on previous pages
  if (0 != $seekCount)
  {
    if (!(mysql_data_seek($result, $seekCount)))
      showDbError();
  }

  // print '<div class="debug">Displaying output</div>' . "\n";

  print '  <tr>' . "\n";
  print "\n";
  print '    <td width="10" height="33" bgcolor="#547CAD">&nbsp;</td>' . "\n";
  print '    <td width="176" bgcolor="#547CAD">&nbsp;</td>' . "\n";
  print '    <td width="35" bgcolor="#547CAD">&nbsp;</td>' . "\n";
  print '    <td width="270" bgcolor="#547CAD"><div align="center"><span class="style46">';

  displayNavigation($pageCount, $currentPage);

  print '</span></div></td>' . "\n";
  print '    <td width="110" bgcolor="#547CAD">&nbsp;</td>' . "\n";
  print '  </tr>' . "\n";

  displayProperties($result, $currentProperty, $propertyCount);

  print '  <tr>' . "\n";
  print "\n";
  print '    <td height="57">&nbsp;</td>' . "\n";
  print '    <td>&nbsp;</td>' . "\n";
  print '    <td>&nbsp;</td>' . "\n";
  print '    <td width="270" bgcolor="#547CAD"><div align="center"><span class="style46">';

  displayNavigation($pageCount, $currentPage);

  print '</span></div></td>' . "\n";

  print '    <td>&nbsp;</td>' . "\n";
  print '  </tr>' . "\n";
?>

Janey Bad XXX
 
Looks like just changing this line
Code:
 $query = "SELECT PropertyID, PropertyName, Price, ShortDescription FROM listings";
to use the Where clause similar to the one that ingresman suggested earlier.
Code:
 $query = "SELECT PropertyID, PropertyName, Price, ShortDescription FROM listings WHERE myfield_containing_student LIKE 'STUDENT LET%' ";

You will need to change myfield_containing_student to the actual fieldname that contains the STDENT LET bit of coourse!

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thank you so much for the help so far but was wondering how to link to the second page of student properties, as at the moment the page links just goes back to Properties.php.

Look forward to your reply.

Kind Regards

Janey Bad XXX
 
Got it working myself but thank you everyone for all your help.

Best Wishes

Janey Bad XXX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top