Jump to content


Photo

SOLVED 2 Repeat Regions


  • Please log in to reply
71 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 08:48 AM

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

<?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 />';
        }
    }
}
}
?>

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



#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 13 September 2006 - 08:53 AM

Yeah,

'or die(mysql_error));'

change to

'or die(mysql_error());'


follow me on twitter @PHPsycho

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 08:55 AM

Try this:

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

I don't need your script, I'll try to write it myself

#4 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 08:56 AM

oops, I am to slow  :)
I don't need your script, I'll try to write it myself

#5 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 08:59 AM

Thanks a lot, That seems to of fixed that error, but inow have another error

of this line

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

which is

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

#6 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 09:04 AM

That's becouse you use one variable name to define query and result. Try something like this:

$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))

I don't need your script, I'll try to write it myself

#7 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 09:08 AM

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

#8 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 09:10 AM

no problem  ;)
yes, just change the name of second query as I did...
I don't need your script, I'll try to write it myself

#9 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 09:14 AM

<?
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 />";
}
}
}
?>

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

#10 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 09:19 AM

That code looks ok, what do you mean to change Q bit?
I don't need your script, I'll try to write it myself

#11 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 09:23 AM

i just got a bit confised, i understnad now, although this code still brings up an error from this line

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

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

#12 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 09:36 AM

Try this:

<?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 />';
}
}
?>

I don't need your script, I'll try to write it myself

#13 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 09:41 AM

that seems to of solved that probelm but gives me this error

Parse error: parse error, unexpected $ in

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

EDIT: i seem to have this working now with this 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 />';
}
}
?>

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

#14 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 09:51 AM

Try to add WHERE:

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

I don't need your script, I'll try to write it myself

#15 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 09:58 AM

so for example this

<?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 />';
}
}
?>


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

#16 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 10:00 AM

ok, try to remove ASC at the end:

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

I don't need your script, I'll try to write it myself

#17 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 10:03 AM

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

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


#18 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 10:07 AM

sorry for the double post, but other querys seem to be like this

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

if that helps at all

#19 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 13 September 2006 - 10:08 AM

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.

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

I don't need your script, I'll try to write it myself

#20 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 September 2006 - 10:09 AM

Is there a column called ID in the table called ID?

Regards
Rich

Edit: Ooops, beaten to it...
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users