PHP Mysql Outputting Records Repeatedly.

Would be grateful for any help.

I have not messed with php/mysql in a while and have come up with a
problem I have run up against before but cannot remember the solution.

See the following page:

http://www.paraisolpraia.com/index_pt.php?content=3Dsel_hote l_pt

I am calling two records from a mysql database with a php script but
as you can see the records are looping and printing repeatedly.

The code I am using is as follows:

"
<?php

require_once('xxxxxx.php');

$prop_sel_1 =3D "SELECT
CASAS.area_id,CASAS.casa_id,CASAS.casa_nom,CASAS.quartos,CAS AS.pessoas,CASAS=
..preco_natal,CASAS.preco_jan,CASAS.preco_fev,CASAS.preco_ma r,CASAS.preco_abr=
,CASAS.preco_mai,CASAS.
preco_jun,CASAS.preco_jul,CASAS.preco_ago,CASAS.preco_set,CA SAS.preco_out,CA=
SAS.preco_nov,CASAS.preco_dez,CASAS.preco_pascoa,CASAS.casa_ text_pt,CASAS.fo=
rm_url_pt,CASAS.cas_img_ref_1,CASAS.active,CASAS.hotel,TOWNS .area_id,TOWNS.n=
ame,TOWNS.text_pt,TOWNS.text_2_pt,TOWNS.img_ref_2
FROM CASAS,TOWNS WHERE CASAS.hotel=3D'Yes' LIMIT 0, 8";
$prop_sel_2 =3D mysql_query($prop_sel_1) or die(mysql_error());
while($prop_sel_3 =3D mysql_fetch_array($prop_sel_2,MYSQL_ASSOC ))
{

Print "<tr>";
Print "<td colspan=3D\"8\" align=3D\"center\"><img alt=3D\" \" align=3D\"cen=
ter
\" src=3D\"images/prop_baa.jpg\" vspace=3D\"2\"></td>";
Print "</tr>";
Print "<tr>";
Print "<td></td>";
Print "<td colspan=3D\"6\">";
Print "<table border=3D\"0\" cellpadding=3D\"0\" cellspacing=3D\"0\" width=
=3D
\"99%\" align=3D\"center\">";
Print "<tr>";
Print "<td><div align=3D\"left\" class=3D\"title_index\">" .
$prop_sel_3['casa_nom'] . "</div></td>";
$foto=3D$prop_sel_3['casa_id'];
$fotos=3D"index.php?content=3Dsel_prop_foto&casa_id=3D$foto" ;
Print "<td><div align=3D\"right\" class=3D\"top_menu\"><a href=3D\"$fotos\"
target=3D\"_blank\" class=3D\"top_menu\">Ver fotografias, clique aqui!</
div></td>";
Print "</tr>";
Print "<tr height=3D\"20\">";
Print "<td colspan=3D\"8\" valign=3D\"middle\"><hr size=3D\"1\" align=3D
\"center\" NOSHADE></td>";
Print "</tr>";
Print "<tr>";
Print "<td valign=3D\"middle\"><div align=3D\"justify\" class=3D\"casa_text
\"><a href=3D" . $prop_sel_3['form_url_pt'] ." class=3D\"casa_text\">".
$prop_sel_3['casa_text_pt'] . "</a></div></td>";
Print "<td rowspan=3D\"2\" align=3D\"right\" valign=3D\"top\"><img src=3D
\"images/".$prop_sel_3['cas_img_ref_1']."\" hspace=3D\"3\" vspace=3D
\"4\"></td>";
Print "</tr>";
Print "<tr>";
Print "<td>";
Print "<table border=3D\"0\" cellpadding=3D\"0\" cellspacing=3D\"0\" width=
=3D
\"95%\" align=3D\"center\">";
Print "<tr>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\">Pessoas " .
$prop_sel_3['pessoas'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\">Quartos " .
$prop_sel_3['quartos'] . "</div></td>";
Print "</tr>";
Print "</table>";
Print "</td>";
Print "</tr>";
Print "<tr>";
Print "<td colspan=3D\"2\">";
Print "<table border=3D\"0\" cellpadding=3D\"1\" cellspacing=3D\"1\" width=
=3D
\"95%\" align=3D\"center\">";
Print "<tr height=3D\"20\">";
Print "<td colspan=3D\"7\" valign=3D\"top\"><div align=3D\"left\" class=3D
\"price_head\"><strong>Preços por semana:</strong></div></td>";
Print "</td>";
Print "</tr>";
Print "<tr>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Janeiro
<br> €" . $prop_sel_3['preco_jan'] . "</div></td>";
Print "<td><div class=3D\"price_yellow\"> Fevreiro <br> €" .
$prop_sel_3['preco_fev'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Mar=E7o <br>=

€" . $prop_sel_3['preco_mar'] . "</div></td>";
Print "<td><div class=3D\"price_yellow\"> Abril <br> €" .
$prop_sel_3['preco_abr'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Maio <br>
€" . $prop_sel_3['preco_mai'] . "</div></td>";
Print "<td><div class=3D\"price_yellow\"> Junho <br> €" .
$prop_sel_3['preco_jun'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Pascoa.
<br> €" . $prop_sel_3['preco_pascoa'] . "</div></td>";
Print "</tr>";
Print "<tr>";
Print "<td><div class=3D\"price_yellow\"> Julho <br> €" .
$prop_sel_3['preco_jul'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Agosto
<br> €" . $prop_sel_3['preco_ago'] . "</div></td>";
Print "<td><div class=3D\"price_yellow\"> Setembro <br> €" .
$prop_sel_3['preco_set'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Octobro
<br> €" . $prop_sel_3['preco_out'] . "</div></td>";
Print "<td><div class=3D\"price_yellow\"> Novembro <br> €" .
$prop_sel_3['preco_nov'] . "</div></td>";
Print "<td bgcolor=3D\"#ffa200\"><div class=3D\"price_yellow\"> Dezembro
<br> €" . $prop_sel_3['preco_dez'] . "</div></td>";
Print "<td><div class=3D\"price_yellow\"> Natal <br> €" .
$prop_sel_3['preco_natal'] . "</div></td>";
Print "</tr>";
Print "</table>";
Print "</td>";
Print "</tr>";
Print "</table>";
Print "</td>";
Print "</tr>";

}
mysql_free_result($result);

?>"

Where I am going wrong??????????

Many thanks for any help for this dumbo!
cgkh.webservices [ Mi, 16 Januar 2008 10:34 ] [ ID #1909634 ]

Re: PHP Mysql Outputting Records Repeatedly.

cgkh.webservices wrote:
> Would be grateful for any help.
>
> I have not messed with php/mysql in a while and have come up with a
> problem I have run up against before but cannot remember the solution.
>
> See the following page:
>
> http://www.paraisolpraia.com/index_pt.php?content=sel_hotel_ pt
>
> I am calling two records from a mysql database with a php script but
> as you can see the records are looping and printing repeatedly.
>
> The code I am using is as follows:
>
> "
> <?php
>
> require_once('xxxxxx.php');
>
> $prop_sel_1 = "SELECT
> CASAS.area_id,CASAS.casa_id,CASAS.casa_nom,CASAS.quartos,CAS AS.pessoas,CASAS.preco_natal,CASAS.preco_jan,CASAS.preco_fev ,CASAS.preco_mar,CASAS.preco_abr,CASAS.preco_mai,CASAS.
> preco_jun,CASAS.preco_jul,CASAS.preco_ago,CASAS.preco_set,CA SAS.preco_out,CASAS.preco_nov,CASAS.preco_dez,CASAS.preco_pa scoa,CASAS.casa_text_pt,CASAS.form_url_pt,CASAS.cas_img_ref_ 1,CASAS.active,CASAS.hotel,TOWNS.area_id,TOWNS.name,TOWNS.te xt_pt,TOWNS.text_2_pt,TOWNS.img_ref_2
> FROM CASAS,TOWNS WHERE CASAS.hotel='Yes' LIMIT 0, 8";
> $prop_sel_2 = mysql_query($prop_sel_1) or die(mysql_error());
> while($prop_sel_3 = mysql_fetch_array($prop_sel_2,MYSQL_ASSOC ))
> {
>
> Print "<tr>";
> Print "<td colspan=\"8\" align=\"center\"><img alt=\" \" align=\"center
> \" src=\"images/prop_baa.jpg\" vspace=\"2\"></td>";
> Print "</tr>";
> Print "<tr>";
> Print "<td></td>";
> Print "<td colspan=\"6\">";
> Print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=
> \"99%\" align=\"center\">";
> Print "<tr>";
> Print "<td><div align=\"left\" class=\"title_index\">" .
> $prop_sel_3['casa_nom'] . "</div></td>";
> $foto=$prop_sel_3['casa_id'];
> $fotos="index.php?content=sel_prop_foto&casa_id=$foto";
> Print "<td><div align=\"right\" class=\"top_menu\"><a href=\"$fotos\"
> target=\"_blank\" class=\"top_menu\">Ver fotografias, clique aqui!</
> div></td>";
> Print "</tr>";
> Print "<tr height=\"20\">";
> Print "<td colspan=\"8\" valign=\"middle\"><hr size=\"1\" align=
> \"center\" NOSHADE></td>";
> Print "</tr>";
> Print "<tr>";
> Print "<td valign=\"middle\"><div align=\"justify\" class=\"casa_text
> \"><a href=" . $prop_sel_3['form_url_pt'] ." class=\"casa_text\">".
> $prop_sel_3['casa_text_pt'] . "</a></div></td>";
> Print "<td rowspan=\"2\" align=\"right\" valign=\"top\"><img src=
> \"images/".$prop_sel_3['cas_img_ref_1']."\" hspace=\"3\" vspace=
> \"4\"></td>";
> Print "</tr>";
> Print "<tr>";
> Print "<td>";
> Print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=
> \"95%\" align=\"center\">";
> Print "<tr>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\">Pessoas " .
> $prop_sel_3['pessoas'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\">Quartos " .
> $prop_sel_3['quartos'] . "</div></td>";
> Print "</tr>";
> Print "</table>";
> Print "</td>";
> Print "</tr>";
> Print "<tr>";
> Print "<td colspan=\"2\">";
> Print "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=
> \"95%\" align=\"center\">";
> Print "<tr height=\"20\">";
> Print "<td colspan=\"7\" valign=\"top\"><div align=\"left\" class=
> \"price_head\"><strong>Preços por semana:</strong></div></td>";
> Print "</td>";
> Print "</tr>";
> Print "<tr>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Janeiro
> <br> €" . $prop_sel_3['preco_jan'] . "</div></td>";
> Print "<td><div class=\"price_yellow\"> Fevreiro <br> €" .
> $prop_sel_3['preco_fev'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Março <br>
> €" . $prop_sel_3['preco_mar'] . "</div></td>";
> Print "<td><div class=\"price_yellow\"> Abril <br> €" .
> $prop_sel_3['preco_abr'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Maio <br>
> €" . $prop_sel_3['preco_mai'] . "</div></td>";
> Print "<td><div class=\"price_yellow\"> Junho <br> €" .
> $prop_sel_3['preco_jun'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Pascoa.
> <br> €" . $prop_sel_3['preco_pascoa'] . "</div></td>";
> Print "</tr>";
> Print "<tr>";
> Print "<td><div class=\"price_yellow\"> Julho <br> €" .
> $prop_sel_3['preco_jul'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Agosto
> <br> €" . $prop_sel_3['preco_ago'] . "</div></td>";
> Print "<td><div class=\"price_yellow\"> Setembro <br> €" .
> $prop_sel_3['preco_set'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Octobro
> <br> €" . $prop_sel_3['preco_out'] . "</div></td>";
> Print "<td><div class=\"price_yellow\"> Novembro <br> €" .
> $prop_sel_3['preco_nov'] . "</div></td>";
> Print "<td bgcolor=\"#ffa200\"><div class=\"price_yellow\"> Dezembro
> <br> €" . $prop_sel_3['preco_dez'] . "</div></td>";
> Print "<td><div class=\"price_yellow\"> Natal <br> €" .
> $prop_sel_3['preco_natal'] . "</div></td>";
> Print "</tr>";
> Print "</table>";
> Print "</td>";
> Print "</tr>";
> Print "</table>";
> Print "</td>";
> Print "</tr>";
>
> }
> mysql_free_result($result);
>
> ?>"
>
> Where I am going wrong??????????
>
> Many thanks for any help for this dumbo!
>
>
>
>

Fix you SQL query.

Try running your query from a MySQL command line prompt (or in
PHPMyAdmin) and see what you get.

If you still can't find it, try a MySQL newsgroup such as
comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mi, 16 Januar 2008 13:00 ] [ ID #1909635 ]

Re: PHP Mysql Outputting Records Repeatedly.

cgkh.webservices wrote:
> Would be grateful for any help.
>
> I have not messed with php/mysql in a while and have come up with a
> problem I have run up against before but cannot remember the solution.
>
> <?php
>
> require_once('xxxxxx.php');
>
> $prop_sel_1 = "SELECT
> CASAS.area_id,CASAS.casa_id,CASAS.casa_nom,CASAS.quartos,CAS AS.pessoas,CASAS.preco_natal,CASAS.preco_jan,CASAS.preco_fev ,CASAS.preco_mar,CASAS.preco_abr,CASAS.preco_mai,CASAS.
> preco_jun,CASAS.preco_jul,CASAS.preco_ago,CASAS.preco_set,CA SAS.preco_out,CASAS.preco_nov,CASAS.preco_dez,CASAS.preco_pa scoa,CASAS.casa_text_pt,CASAS.form_url_pt,CASAS.cas_img_ref_ 1,CASAS.active,CASAS.hotel,TOWNS.area_id,TOWNS.name,TOWNS.te xt_pt,TOWNS.text_2_pt,TOWNS.img_ref_2
> FROM CASAS,TOWNS WHERE CASAS.hotel='Yes' LIMIT 0, 8";

Hi,

PhP and MySQL/SQL are not my tongue languages but I think I can help you
on this.

Try changing your WHERE clausule in your query to:
....WHERE CASAS.hotel='Yes' and CASAS.area_id = TOWNS.area_id LIMIT 0,8";

Of course I didn't test it, but I bet it helps.

Good luck!

Ramon Rabaso
http://www.realtimequery.com - Live Help for Websites.
Ramon Rabaso [ Do, 17 Januar 2008 12:17 ] [ ID #1910685 ]
PHP » alt.php » PHP Mysql Outputting Records Repeatedly.

Vorheriges Thema: auto-generating form value permutations..
Nächstes Thema: File download with progress bar/indicator?