Jump to content

Recommended Posts

I need to adapt the following code (which displays all vehicles with the same model as the displayed vehicle) for two separate purposes:

 

a) Exclude the vehicle that is currently being viewed. The Key value is their stock number, I would like to somehow do

SELECT * FROM vehicles WHERE model=$model "EXCLUDING stock=$stock"

 

b) I need to use this code to display a SEPARATE box that shows vehicles with prices within $2000 of the currently displayed vehicle.

ie:

 SELECT * FROM vehicles WHERE price="BETWEEN ($price - 2000) ($price + 2000)"

 

 

<?php
				//Make first query to database
				$query = "SELECT * FROM vehicles";
				$result = mysql_query($query)
					or die ("Couldn’t execute query.");

				//Set Variables
				$vehiclemodel = $vehicles->model->ViewValue;
				$show_price = number_format($vehicles->price->ViewValue);
				$query = "SELECT * FROM vehicles WHERE model='$vehiclemodel'";
				$result = mysql_query($query)
					or die ("Couldn't execute query.");

				// Display results in a table

				echo "<tr><td colspan='5'></td></tr>";
				while ($row = mysql_fetch_array($result))
				{
				extract($row);

				//Table Contents
				echo "<tr class='dataright'>\n
				<td colspan='5' class='dataleft'><a href='view.php?stock=$stock'>$year $model</a></td>\n
				<td>$odometer km  </td>\n
				<td align='right'>$$show_price.00</td>\n
				</tr>\n";
				echo "<tr><td colspan='3'></td></tr>\n";
				}
			?>

 

Any help would be much appreciated as I am very close to finalizing this project, I'm a bit of a new comer to PHP but I'm learning quick.

 

Thanks!

One problem:

 

			<?php
				//Make first query to database
				$query = "SELECT * FROM vehicles";
				$result = mysql_query($query)
					or die ("Couldn’t execute query.");

				//Set Variables
				$vehiclemodel = $vehicles->model->ViewValue;

				$query = "SELECT * FROM vehicles WHERE model='$vehiclemodel'";
				$result = mysql_query($query)
					or die ("Couldn't execute query.");

				// Display results in a table

				echo "<tr><td colspan='5'></td></tr>";
				while ($row = mysql_fetch_array($result))
				{
				extract($row);

				//Table Contents
				$show_price = number_format($price);
				echo "<tr class='dataright'>\n
				<td colspan='5' class='dataleft'><a href='view.php?stock=$stock'> $year $model</a></td>\n
				<td>$odometer km  </td>\n
				<td align='right'>$$show_price.00 </td>\n
				</tr>\n";
				echo "<tr><td colspan='3'></td></tr>\n";
				}
			?>






     		 
<!--end right column Make-->
<!--start right column Model-->		   	
     
    <tr>
   <td colspan="7" class="pcdrb">Other <?php echo $vehicles->make->ViewValue ?>s</td>
    </tr> 
			<?php
				//Make first query to database
				$query = "SELECT * FROM vehicles";
				$result = mysql_query($query)
					or die ("Couldn’t execute query.");

				//Set Variables
				$query = "SELECT * FROM vehicles WHERE make= '$make' AND stock != '$stock'";
				$result = mysql_query($query)
					or die ("Couldn't execute query.");

				// Display results in a table

				echo "<tr><td colspan='5'></td></tr>";
				while ($row = mysql_fetch_array($result))
				{
				extract($row);

				//Table Contents
				$show_price = number_format($price);
				echo "<tr class='dataright'>\n
				<td colspan='5' class='dataleft'><a href='view.php?stock=$stock'> $year $model</a></td>\n
				<td>$odometer km  </td>\n
				<td align='right'>$$show_price.00 </td>\n
				</tr>\n";
				echo "<tr><td colspan='3'></td></tr>\n";
				}

			?>


     
<!--end right column Model-->

<!--start right column Other +-2000-->
     
    <tr>
   <td colspan="7" class="pcdrb">Other <?php echo $vehicles->type->ViewValue ?>s ± $2,000.00</td>
    </tr>	

			<?php
				//Make first query to database
				$query = "SELECT * FROM vehicles";
				$result = mysql_query($query)
					or die ("Couldn’t execute query.");

				//Set Variables
				$query = "SELECT * FROM `vehicles` WHERE `price` >= ($price - 2000) AND `price` <= ($price + 2000)";
				$result = mysql_query($query)
					or die ("Couldn't execute query.");

				// Display results in a table

				echo "<tr><td colspan='5'></td></tr>";
				while ($row = mysql_fetch_array($result))
				{
				extract($row);

				//Table Contents
				$show_price = number_format($price);
				echo "<tr class='dataright'>\n
				<td colspan='5' class='dataleft'><a href='view.php?stock=$stock'> $year $model</a></td>\n
				<td>$odometer km  </td>\n
				<td align='right'>$$show_price.00 </td>\n
				</tr>\n";
				echo "<tr><td colspan='3'></td></tr>\n";
				}

			?>

 

I have these three separate tables.

Pricing one (last one) works great.

Make (middle one) works great.

As soon as I try to add the code

SELECT * FROM `vehicles` WHERE `model` = '{$model}' AND `stock` != '{$stock}'

to the first one, which is the Similiar Models table, all three of them break and my checkboxes later in the page also all show no results.

Is using this statement for make and model both somehow causing a problem?

in the sql use $vehiclemodel instead of $model I'm assuming anyway

 

Meaning I should be changing it in the database itself?

The $model has worked everywhere else..

I'll look into it. The IE issue you helped me with is more pressing at this time.

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.