Re: Conditional search from two tables?
| From: | Éles Zoltán | Date: | Wed, 20 Sep 2000 11:00:08 +0000 |
| Subject: | Re: Conditional search from two tables? | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-2993@lists.php.net to get a copy of this message | ||
Try this:
mysql_query("SELECT * FROM kommentar WHERE id={$myrow8->id}) ", $db);
^ ^
bye
zeles
> > I have a MySQL table called "adresse" with a tinyint row called "id".
> > I
want to use it in a second search in another table, "kommentar", wich also
has a tinyint row called "id". I used this script:
> >
> > $result8 = mysql_query("SELECT * FROM adresse WHERE
(gate='$gt')",$db);
> > while ($myrow8 = mysql_fetch_array($result8)) {
> > echo $myrow8["id"];
> > $result9 = mysql_query("SELECT * FROM kommentar WHERE
(id=$myrow8["id"]) ", $db);
> > $myrow9 = mysql_fetch_array($result9);
> > echo $myrow9["id"];
> > }
>
> You could use mysql_fetch_object so the above becomes;
>
> $result8 = mysql_query("SELECT * FROM adresse WHERE (gate='$gt')",$db);
> while ($myrow8 = mysql_fetch_object($result8)) {
> echo $myrow8->id;
> $result9 = mysql_query("SELECT * FROM kommentar WHERE id=$myrow8->id)
", $db);
> $myrow9 = mysql_fetch_array($result9);
> echo $myrow9->id;
> }
>
> try that.
>
> paul
>
> >
> > This gave the following error:
> >
> > "Parse error: parse error, expecting
STRING' or
> > NUM_STRING' or `'$''
in
> > /home/httpd/html/script/side2.php3 on line 68"
> >
> > It works ok if I put in (id=2) instead of (id=$myrow8["id"])
> >
> > (it prints out my first id value in both cases, but it halted on the
second when the error came).
> >
> > Why cant I use (id=$myrow8["id"]) here? and how can I pick out values
from the second db based on the first search ?
> >
> > I think I have now understood the point in differentiating between char
and int which David Robley and zeles pointed out to me after my last
question. (Now the char variable is working nice in my first search
statement)
> >
> > --
> > Knut Lekvam
> >
> > __________________________________________________________________
> >
> > Denne eposten er sendt ved hjelp av
> > http://www.Organizer.net
> > - Norges ledende webbaserte kommunikasjonsløsning.
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-db-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
> --
> ------------------------------------------------------------
> Paul Cooper | Tel: 0121 687 3024
> Software and Database Developer | Fax: 0121 687 3001
> UCEcom | email: pgc@ucecom.com
> University of Central England |
> Birmingham, B4 7DX |
> ------------------------------------------------------------
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>