Jump to content

Trouble with this script :( any help?


mongoose00318

Recommended Posts

Hey all,

 

I am trying to get this script to output this data how I want. I want the table to rotate classes on each <tr> to make the rows different colors. I got it working fine on my other pages, but this one has a complicated sql query that is making it hard for me to figure out how to run the loop. If you could take a look at it and try to help me out that would be great! I have noted the part that I have been trying to run the loop in with /////// on top and bottom of the code for easier reading.

 

<?php
    //include dbconfig
       require_once('includes/dbconfig.php');
       //create varibles for getting the news postings from the db
       $communities_query = 'SELECT * FROM communities';
   $listings_query = 'SELECT * FROM listings';
       $communities_result = mysql_query($communities_query);
   $current_community = ""; 
   $result = mysql_query("SELECT communities.name, communities.city AS c_city, communities.state AS c_state, communities.price_range AS c_price_range, communities.features AS c_features, communities.phone AS c_phone, communities.email AS c_email, communities.directions AS c_directions, communities.description AS c_description, listings.title, listings.city AS l_city, listings.id AS l_id, listings.state AS l_state, listings.sq_ft AS l_sq_ft, listings.price AS l_price FROM communities, listings WHERE (communities.id = listings.community_id) && (listings.quick_movein = 'Yes') ORDER BY communities.id ASC");
   $number_of_listings = mysql_num_rows($result);
   if($number_of_listings > 0) {
	   while($row = mysql_fetch_array($result)) { 
			if($row['name'] != $current_community) {
				$current_community = $row['name']; 
				echo('
				 <br>
                 <span class="community_title">'.ucfirst($current_community).'</span> <span class="location">'.ucfirst($row['c_city']).', '.ucfirst($row['c_state']).'</span>
			 <div class="divider"></div>
			 <span class="general_info">Price Range:</span> <span class="general_values">'.ucfirst($row['c_price_range']).'</span><span class="general_info">Phone:</span> <span class="general_values">'.$row['c_phone'].'</span><span class="general_info">Email:</span> <a href="mailto:'.$row['c_email'].'" class="email_link">'.$row['c_email'].'</a>
                 <div class="general_links_container">
			 <a href="community_features/'.$row['c_features'].'" class="general_links">Standard Features</a> | <a href="view_inventory.php?community_id='.$row['id'].'" class="general_links">View Current Inventory</a> | <a href="directions/'.$row['c_directions'].'" class="general_links">Community Details / Directions</a>
			 </div>
			 <span class="general_info">Community Summary</span>
			 <br />
                 <span class="community_summary">'.ucfirst($row['c_description']).'</span>
			 <div class="divider"></div>
			 <span class="floorplan_title">Floorplans</span> <span class="general_info">click on plan name for details</span>
			 <br />
			 /////////////////////////////////////////////////////////////
                                                    <table border="0" cellspacing="0" cellpadding="0">
			 '
                 );
			 $tracker = 0;
			 while ($row = mysql_fetch_array($result)) {
					echo ('
					<tr class="row'.$tracker.'">
						<td class="cell_spacing"><a href="view_listing.php?listing_number='.$row['l_id'].'" class="specfic_info">'.ucfirst($row['title']).'</a></td>
						<td class="cell_spacing"><span class="specfic_info">Square Footage: '.ucfirst($row['l_sq_ft']).'</span></td>
						<td class="cell_spacing"><span class="specfic_info">Base Price: $'.ucfirst($row['l_price']).'</span></td>
					</tr>
						');
					$tracker = 1 - $tracker;
					}
                                                                             ///////////////////////////////////////////////////////////////

Link to comment
Share on other sites

<?php
    //include dbconfig
    require_once('includes/dbconfig.php');
    //create varibles for getting the news postings from the db
    $communities_query = 'SELECT * FROM communities';
    $communities_result = mysql_query($communities_query);
    $current_community = ""; 
    $result = mysql_query("SELECT communities.name, communities.city AS c_city, communities.state AS c_state, communities.price_range AS c_price_range, communities.features AS c_features, communities.phone AS c_phone, communities.email AS c_email, communities.directions AS c_directions, communities.description AS c_description, listings.title, listings.city AS l_city, listings.id AS l_id, listings.state AS l_state, listings.sq_ft AS l_sq_ft, listings.price AS l_price FROM communities, listings WHERE (communities.id = listings.community_id) && (listings.quick_movein = 'Yes') ORDER BY communities.id ASC");
    $number_of_listings = mysql_num_rows($result);
    if($number_of_listings > 0) {
         while($row = mysql_fetch_array($result)) { 
  if($row['name'] != $current_community) {
        $current_community = $row['name']; 
	echo('
	        <br>
                                 <span class="community_title">'.ucfirst($current_community).'</span> <span class="location">'.ucfirst($row['c_city']).', '.ucfirst($row['c_state']).'</span>
                                 <div class="divider"></div>
	       <span class="general_info">Price Range:</span> <span class="general_values">'.ucfirst($row['c_price_range']).'</span><span class="general_info">Phone:</span> <span class="general_values">'.$row['c_phone'].'</span><span class="general_info">Email:</span> <a href="mailto:'.$row['c_email'].'" class="email_link">'.$row['c_email'].'</a>
                                 <div class="general_links_container">
                    <a href="community_features/'.$row['c_features'].'" class="general_links">Standard Features</a> | <a href="view_inventory.php?community_id='.$row['id'].'" class="general_links">View Current Inventory</a> | <a href="directions/'.$row['c_directions'].'" class="general_links">Community Details / Directions</a>
	        </div>
	        <span class="general_info">Community Summary</span>
	        <br />
                                  <span class="community_summary">'.ucfirst($row['c_description']).'</span>
                     <div class="divider"></div>
	        <span class="floorplan_title">Floorplans</span> <span class="general_info">click on plan name for details</span>
	        <br />
	        <table border="0" cellspacing="0" cellpadding="0">
                                  ');
	$tracker = 0;
	while ($row = mysql_fetch_array($result)) {
	        echo ('
		   <tr class="row'.$tracker.'">
		      <td class="cell_spacing"><a href="view_listing.php?listing_number='.$row['l_id'].'" class="specfic_info">'.ucfirst($row['title']).'</a></td>
		      <td class="cell_spacing"><span class="specfic_info">Square Footage: '.ucfirst($row['l_sq_ft']).'</span></td>
		      <td class="cell_spacing"><span class="specfic_info">Base Price: $'.ucfirst($row['l_price']).'</span></td>
		   </tr>
		    ');
	         $tracker = 1 - $tracker;
	         }

 

I tryed to clean the code up a bit for ya'll. Hopefully it helps in getting a response.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.