Jump to content

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

Link to comment
https://forums.phpfreaks.com/topic/20597-solved-2-repeat-regions/
Share on other sites

  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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]
[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
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
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]
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
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
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]
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
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
[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
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
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.