RSS Forums RSS
Please support our MySQL advertiser: Programming Forums
Views: 904 | Replies: 3 | Thread Tools  Display Modes
Reply
Join Date: Oct 2007
Posts: 2
Reputation: Lucky13MN is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Lucky13MN Lucky13MN is offline Offline
Newbie Poster

PHP/MySQL Help Needed

  #1  
Oct 19th, 2007
I have script that is almost done, I just need
help with one more thing.

I'll describe the relevant structure the best I can, then explain what I need.

TABLE carlot
FIELDS trackpt, id

TABLE cars
FIELD userid, carid

TABLE grpusers
FIELD id

Field id from table carlot = field carid from table cars
Field userid from table cars = field id from table grpusers

The value I need to display is in the field trackpt, what PHP code do I need to get this value (associated with the userid).

What I am trying to do is add that value to other values in the grpusers table.

Any suggestions? I'm sure this isn't difficult for people that work with php and mysql a lot but this is day 3 for me with no formal training and I'm basically tweaking code to make this work.

Any help is greatly appreciated!
Last edited by Lucky13MN : Oct 19th, 2007 at 11:49 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: PHP/MySQL Help Needed

  #2  
Oct 20th, 2007
Presumably you want an inner join?

Let's assume the table carlot is:

+---------+----+
| trackpt | id |
+---------+----+
| blah    |  1 | 
| wah     |  2 | 
| woot    |  3 | 
+---------+----+

And the table cars is:

+--------+-------+
| userid | carid |
+--------+-------+
|      1 |     3 | 
|      2 |     5 | 
|      3 |     5 | 
+--------+-------+

Now you want to link the two by carlot(id) and cars(userid).

Thus...

mysql> SELECT trackpt, carid FROM carlot
    -> INNER JOIN cars ON carlot.id = cars.userid;
+---------+-------+
| trackpt | carid |
+---------+-------+
| blah    |     3 | 
| wah     |     5 | 
| woot    |     5 | 
+---------+-------+
3 rows in set (0.01 sec)
Last edited by iamthwee : Oct 20th, 2007 at 9:08 am.
*Voted best profile in the world*
Reply With Quote  
Join Date: Oct 2007
Posts: 2
Reputation: Lucky13MN is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Lucky13MN Lucky13MN is offline Offline
Newbie Poster

Re: PHP/MySQL Help Needed

  #3  
Oct 20th, 2007
Thank you very much, you make it look so easy.

I get this:
Parse error: syntax error, unexpected T_STRING in /home/l1376/public_html/folder/citizens.php on line 4

Line 4 is/was:
mysql> SELECT trackpt, carid FROM carlot

Also, once this is working what code is needed to use 'trackpt' in an equation? Such as HP + trackpt = $challengerpts

Thank you so much...
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: PHP/MySQL Help Needed

  #4  
Oct 21st, 2007
Originally Posted by Lucky13MN View Post
Thank you very much, you make it look so easy.

I get this:
Parse error: syntax error, unexpected T_STRING in /home/l1376/public_html/folder/citizens.php on line 4

Line 4 is/was:
mysql> SELECT trackpt, carid FROM carlot

Also, once this is working what code is needed to use 'trackpt' in an equation? Such as HP + trackpt = $challengerpts

Thank you so much...


Try:-

  1. <?php
  2. $conn = mysql_connect("localhost","username","yourpassword");
  3. //pick the database to use
  4. mysql_select_db("test",$conn);
  5. //create sql statement
  6. $sql = "SELECT trackpt, carid FROM carlot INNER JOIN cars ON carlot.id = cars.userid";
  7. //execute statement
  8. $result = mysql_query($sql, $conn) or die(mysql_error());
  9. //go through each row in the result set and display data
  10. while ( $newArray = mysql_fetch_array($result) )
  11. {
  12. //give a name to the fields
  13. $id = $newArray['trackpt'];
  14. $testField = $newArray['carid'];
  15. //echo the results to screen
  16. echo " $id $testField <br>";
  17. }
  18. ?>

Obviously replacing username password with your actual username and password.
Last edited by iamthwee : Oct 21st, 2007 at 10:16 am.
*Voted best profile in the world*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the MySQL Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:23 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC