GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Jun-2003, 09:12
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

cant find a sql/php query???


Hi ,
Tables like this:
table title
blabla
titelid,

table rel_user_titel
titelid
userid
usernr

location table
userid
prename
name

And need following:
to show the location, given the titelid i need a myasql
command in for php.
...select from
...
$result or somethin shoult contain
prename, name and userid,

Would be great to get something.


Matthias

ThX
  #2  
Old 26-Jun-2003, 09:39
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Try this:

PHP Code:

<?php

$sql = 'SELECT L.prename, L.name, L.userid
       FROM rel_user_titel AS R, `location` AS L
       WHERE R.titelid = '.$_GET['id'].'
       AND L.userid = R.userid';
?>

  #3  
Old 27-Jun-2003, 02:56
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

Thank you, but a question remains


What do you mean with the letters?
t=title,l=location and what is "R"?
How does this command with "as" works?

Thanx


Matthias
  #4  
Old 27-Jun-2003, 03:02
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

ok


I got it, I will test it
and then post again.

matthias
  #5  
Old 27-Jun-2003, 03:09
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
He's created a query that joins the 2 tables together. Using the AS command, he gives each table a temporary name (R and L), to make it easy to refer to it's contents.

Try to sketch out what happens when the query is run.

RETURN "prename", "name" and "userid" from the 'location' table (L).

WHERE "title_id" of 'rel_user_titel' is a certain value

AND "userid" of 'location' table = "userid" of 'rel_user_titel' table


So it returns the rows of the 2 tables which have the same userid, and has a certain value in "title_id" of 'rel_user_titel'

Hope this helps
GF
  #6  
Old 27-Jun-2003, 03:25
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

I tried it but errors occured


I changed the code to this:
PHP Code:

//query for Standort(location)
         
         $sql = "SELECT Standort.vorname, Standort.name, Standort.userid"
   line 244: "FROM rel_titel_user AS title, 'Standort' AS Standort"
               "WHERE title.titelid = '.$_GET['id']."
               "AND Standort.userid = title.userid";
          $result3 = mysql_query($sql); 


Error**** error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in d:\programme\apache group\apache\htdocs\bibli\find.php on line 244


Matthias
  #7  
Old 27-Jun-2003, 07:02
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
The entire SQL statement should be enclosed by a single pair of double quotes.

Read the error message. There's a string in an unexpected place. It's standing there on it's own, PHP doesn't realise it's part of the SQL.

Change the line to exactly how Jay posted it. I see you played about with it, I'm not sure it's safe to call Standort: Standort. mySql may get confused since you're renaming the table with the same name.

GF
  #8  
Old 27-Jun-2003, 08:26
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

OK, I#ve fixed it


No I need a short while or something construct to
"echo" the prename and the name.

Matthias
  #9  
Old 27-Jun-2003, 08:30
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

Ive tried some thing, but..


always only one name occurs, but i need a echo
like Locationrename name;

Thanx

Matthias
  #10  
Old 27-Jun-2003, 18:29
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

PHP MySQL's while() loop example


try this:

PHP Code:

<?php
$title_id = intval( $_GET['id'] ); /*  Forgot to mention this before...
                                       make sure type is (int); IMPORTANT!  */
$sql = 'SELECT SO.vorname, SO.name, SO.userid
       FROM rel_titel_user AS RTU, Standort AS SO
       WHERE RTU.titelid = '.$title_id.'
       AND S.userid = RTU.userid';
$result3 = mysql_query( $sql );
// I suppose this could return more than one row, huh?
echo "<ol>\\n";
// to extend: use mysql_num_rows() to check if empty or n/a...
while( $row = mysql_fetch_assoc($result3) )
{
  echo     '  <li>Location: '.$row['vorname'].', '.$row['name']."</li>\\n";
}
echo "</ol>\\n";
?>

 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I find web statistics script / software? rhino1616 Web Design Forum 2 02-Jan-2004 21:31
Integrate a mysql query into another norok MySQL / PHP Forum 2 22-Jul-2003 07:25
HELP!: find window width? Center a <div>? Kingherc Web Design Forum 2 06-Jul-2003 06:25
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 11:34
How do I find the Unix log file route? jrobbio Web Hosting Forum 4 04-Feb-2003 08:40

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:27.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.