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
https://forums.phpfreaks.com/topic/217572-displaying-data-from-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.