Jump to content

Displaying data from database


BCAV_WEB

Recommended Posts

Hi,

I'm trying to joing two tables together, in the resulting PHP coding (See below)  the issue I'm having the coding saying select the colour from the colour table where the model of car is the same as the model in the cars table. For example, if the car model is KA and in the table it is KA show the colours.

 

I know this manual fix does the trick.

 

[

$test = "KA";

$query_cols = "SELECT * FROM colours WHERE colours.model = '$test' ";

]

 

 

 

But not the soultion any help would be much appericated thank you.

 

 

[

include "connections/dbconnect.php";

$manfactures = "Ford";

$car_query = "SELECT * FROM cars WHERE make = '$manfactures'";

$car_result = mysql_query($car_query) or die ("Error in query: $car_query. ".mysql_error());

 

setlocale(LC_MONETARY, 'en_GB');

$fmt = '%i';

if (mysql_num_rows($car_result) > 0)

{

 

 

 

while ($car_row = @ mysql_fetch_array($car_result))

{

 

$test = "KA";

$query_cols = "SELECT * FROM colours WHERE colours.model = cars.model";

$cols_result = mysql_query($query_cols) or die ("Error in query: $query_cols. ".mysql_error());

print "

<table class=details'>

<tr>

<td rowspan='2'>

<img src=\"". $car_row["image] ."\" alt='" . $car_row["image_alt"] . "' />

</td>

<td colspan='2'>

<a href='" . $car_row["what_link"] . "'>

" . $car_row["model"]." ".$car_row["model_details"] . "

</a>

</tr>

<tr>

<td>

<p class='info'>

RRP:<br/>

What Price:<br/>

Our Price:<br/>

Savings of:<br/>

Delivery Time:

 

</p>

</td>

<td>

<p class='info1'>

";

echo money_format($fmt, $car_row["rrp"] );

  print "<br/>";

 

echo money_format($fmt, $car_row["what_price"] );

  print "<br/>";

 

echo money_format($fmt, $car_row["our_price"] );

 

  $savings = $car_row["rrp"] - $car_row["our_price"];

  print " <br/>

<font color=\"red\">";

echo money_format($fmt, $savings );

  print " </font><br/>

" . $car_row["delivery_time"] . "

</p>

</td>

</tr>

<tr>

<td>

";

while ($cols_row = @ mysql_fetch_array($cols_result))

{

?>

                                               

 

<a href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $cols_row["colour"] . ""; ?>");return false'>

                                      <?php

print "

<img src=\"". $cols_row["colour_img"] ."\" alt='" . $cols_row["colour_img_alt"] . "' />

  ";

}

  print "

</td>

</tr>

";

}

}

 

 

else

{

echo "Aids!";

}

print "</table>";

 

 

?>]

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.