Jump to content

Archived

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

ltoto

SOLVED 2 Repeat Regions

Recommended Posts

so I am tryin to do something with a repeat region inside another repeat region, i have used the code below

[code]<?php
}

while ($row_rsDeals = mysql_fetch_assoc($rsDeals)) {

if($row_rsPages['Id']== "15")
{

    $row_rsCountry = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or die(mysql_error));
   
    while($row_rsCountry=mysql_fetch_array($row_rsCountry))
    {
        echo '<h2>'. $row_rsCountry['countryName'] .'</h2>';
       
        $row_rsRegion = mysql_query("SELECT * FROM `regionName` WHERE countryName = '".$row_rsCountry['Id']."' ORDER BY `region` ASC") or die(mysql_error());
       
        while($row_rsRegion=mysql_fetch_array($row_rsRegion))
        {
            echo '<br />' . $row_rsRegion['regionName'] . '<br />';
        }
    }
}
}
?>[/code]

so how it works is that there is a list of countrys, and withing the countrys there are a list of regions from that country, when i use this code though, i get this error:

Parse error: parse error, unexpected ')'

which is on this line : $row_rsCountry = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or die(mysql_error));

any suggestions

Share this post


Link to post
Share on other sites
Try this:

[code]$row_rsCountry = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
Thanks a lot, That seems to of fixed that error, but inow have another error

of this line

[code]echo"<h2>"$row_rsCountry['countryName']."</h2>";[/code]

which is

parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';'

Share this post


Link to post
Share on other sites
That's becouse you use one variable name to define query and result. Try something like this:

[code]$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or die(mysql_error));
while($row_rsCountry=mysql_fetch_array($row_rsCountry_Q))[/code]

Share this post


Link to post
Share on other sites
that works, i assume i just do the same kind of thing for the next bit of code now to get this error away:

Parse error: parse error, unexpected T_VARIABLE in

I will give it a go now, thanks alot so far for the help

Share this post


Link to post
Share on other sites
no problem  ;)
yes, just change the name of second query as I did...

Share this post


Link to post
Share on other sites
[code]
<?
if($row_rsPages['Id'] == "15"){
$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or  die(mysql_error());
while($row_rsCountry=mysql_fetch_array($row_rsCountry_Q))
echo $row_rsCountry['countryName'];
$row_rsRegion_Q = mysql_query("SELECT * FROM 'Id' ORDER BY 'regionName'= '"$row_rsCountry['Id']."'ORDER BY `countryName` ASC") or  die(mysql_error());
while($row_rsRegion=mysql_fetch_array($row_rsRegion_Q))
echo"<br />"$row_rsRegion['regionName']."<br />";
}
}
}
?>
[/code]

sorry a little confused, so i have done that, but do i now need to change the Q bit?

sorry im still a bit of a newb

Share this post


Link to post
Share on other sites
i just got a bit confised, i understnad now, although this code still brings up an error from this line

[code]$row_rsRegion_Q = mysql_query("SELECT * FROM 'Id' ORDER BY 'regionName'= '"$row_rsCountry['Id'] "'ORDER BY 'countryName' ASC") or  die(mysql_error());[/code]

the error is
Parse error: parse error, unexpected T_VARIABLE in

Share this post


Link to post
Share on other sites
Try this:

[code]<?php
while ($row_rsDeals = mysql_fetch_assoc($rsDeals)) {

if($row_rsPages['Id']== "15")
{
$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or die(mysql_error());
while($row_rsCountry = mysql_fetch_array($row_rsCountry_Q))
{
echo '<h2>'. $row_rsCountry['countryName'] .'</h2>';
}
$row_rsRegion_Q = mysql_query("SELECT * FROM `regionName` WHERE countryName = '".$row_rsCountry['Id']."' ORDER BY `region` ASC") or die(mysql_error());
while($row_rsRegion = mysql_fetch_array($row_rsRegion_Q))
{
echo '<br />' . $row_rsRegion['regionName'] . '<br />';
}
}
?>[/code]

Share this post


Link to post
Share on other sites
that seems to of solved that probelm but gives me this error

[b]Parse error: parse error, unexpected $ in[/b]

which is the last line of the page with nothing on it

EDIT: i seem to have this working now with this code:

[code]<?php

if($row_rsPages['Id']== "15")
{
$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' ORDER BY 'countryName' ASC") or die(mysql_error());
while($row_rsCountry = mysql_fetch_array($row_rsCountry_Q))
{
echo '<h2>'. $row_rsCountry['countryName'] .'</h2>';
}
$row_rsRegion_Q = mysql_query("SELECT * FROM 'regionName' WHERE 'countryName' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ASC") or die(mysql_error());
while($row_rsRegion = mysql_fetch_array($row_rsRegion_Q))
{
echo '<br />' . $row_rsRegion['regionName'] . '<br />';
}
}
?>[/code]

but have this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Id' ORDER BY 'countryName' ASC' at line 1

Share this post


Link to post
Share on other sites
Try to add WHERE:

[code]$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' WHERE 'id' ORDER BY 'countryName' ASC") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
so for example this

[code]<?php

if($row_rsPages['Id']== "15")
{
$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' WHERE 'Id' ORDER BY 'countryName' ASC") or die(mysql_error());
while($row_rsCountry = mysql_fetch_array($row_rsCountry_Q))
{
echo '<h2>'. $row_rsCountry['countryName'] .'</h2>';
}
$row_rsRegion_Q = mysql_query("SELECT * FROM 'regionName' WHERE 'countryName' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ASC") or die(mysql_error());
while($row_rsRegion = mysql_fetch_array($row_rsRegion_Q))
{
echo '<br />' . $row_rsRegion['regionName'] . '<br />';
}
}
?>[/code]


EDIT: Just noticed that this bring up the same kind of error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Id' WHERE 'Id' ORDER BY 'countryName' ASC' at line 1


sorry for being so thick by the way, normally i would spend time trying to figure it out, but I am running out of time now thats all

Share this post


Link to post
Share on other sites
ok, try to remove ASC at the end:

[code]$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' WHERE 'Id' ORDER BY 'countryName' ") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
i tried that but it just takes that bit off of the error, eg

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Id' WHERE 'Id' ORDER BY 'countryName'' at line 1

so now the code is this

[code]$row_rsCountry_Q = mysql_query("SELECT * FROM 'Id' WHERE 'Id' ORDER BY 'countryName' ") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
sorry for the double post, but other querys seem to be like this

[code]$query_rsVillas = "SELECT * FROM tabPages WHERE Id = 3";
$rsVillas = mysql_query($query_rsVillas, $conTotal) or die(mysql_error());[/code]

if that helps at all

Share this post


Link to post
Share on other sites
hmmm.... Let's try in this way to check out what we are doing wrong:
Hope the Id is a table and there is a feild called Id too.

[code]$row_rsCountry_Q = mysql_query("SELECT * FROM Id WHERE Id") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
Is there a column called ID in the table called ID?

Regards
Rich

[size=8pt][b]Edit:[/b] Ooops, beaten to it...[/size]

Share this post


Link to post
Share on other sites
this error:

Table 'totaltravel.Id' doesn't exist

i think i understand, where it says from Id, i must put the name of the tabe so

tabCountry for example is the name of the country table

EDIT: it seems to be error free now, but nothing is actually showing on the page

Share this post


Link to post
Share on other sites
i made a mistake with the Deals recordset, so the code now is

[code]<?php

if($row_rsPages['Id']== "15")
{
$row_rsCountry_Q = mysql_query("SELECT * FROM tabCountry WHERE 'Id' ORDER BY 'countryName' ") or die(mysql_error());
while($row_rsCountry = mysql_fetch_array($row_rsCountry_Q))
{
echo '<h2>'. $row_rsCountry['countryName'] .'</h2>';
}
$row_rsRegion_Q = mysql_query("SELECT * FROM tabRegion WHERE 'regionName' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ") or die(mysql_error());
while($row_rsRegion = mysql_fetch_array($row_rsRegion_Q))
{
echo '<br />' . $row_rsRegion['regionName'] . '<br />';
}
}
?>[/code]

i cant see why it is not now showing on the page, so maybe someelse can see

Share this post


Link to post
Share on other sites
[code=php:0]
mysql_query("SELECT * FROM tabCountry WHERE 'Id' ORDER BY 'countryName' ") or die(mysql_error());
[/code]

I'm assuming that with this piece of code that you want to select every country?  If so, you can drop the [color=red]WHERE 'id'[/color] as it's not actually doing anything unless you specify something after it, such as [color=red]WHERE id = '$num'[/color]

We seem to be going around the houses here, to help us to help you, can you provide us with your table names and a list of the columns in those tables?

Regards
Rich

Share this post


Link to post
Share on other sites
The country table is:

tabCountry:

id
countryName



and the Region Table is

tabRegion:

id
regionName


there is also a table after this , so when they click on region, the list of hotels on that region appear, on a new page:

tabHotel:

id
hotelName
hotelCountry
hotelRegion
hotelImage
hotelDescription
hotelRating

in the CMS to this, there are drop down menus for The COuntry and Region,  in the hotel section.

I hope this helps

Share this post


Link to post
Share on other sites
OK, now it's starting to make sense, did you design the tables or did you get this script from somewhere as a 'pre-built'?

I think the database design is slightly out.

Regards
Rich

Share this post


Link to post
Share on other sites

×

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.