9 Replies - 592 Views - Last Post: 21 March 2013 - 12:24 PM Rate Topic: -----

#1 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Php echo primary key

Posted 21 March 2013 - 03:26 AM

CprId is a foreign key ..now im getting a number but i want to get the value from the table which is connected(which is text).Which is the easy way to that?


<?php

     $con = mysql_connect("localhost","root","");

     if (!$con)
	 {    
       die('Could not connect: ' . mysql_error());
     }
	 
     mysql_select_db("Mall",$con);
     $result = mysql_query("SELECT * FROM customers");
     echo '<h2>  CUSTOMERS   </h2>';
	   
     while($row = mysql_fetch_array($result))
	 {	 
	   echo $row['CID'].'-'.' '.$row['CSName'].' '.$row['Cname'].' '.
	        $row['SEX'].' '.$row['CPrId'];
	   echo "<br>";
	 }
	 
	 mysql_close($con);
?>



This post has been edited by Dormilich: 21 March 2013 - 03:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Php echo primary key

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3394
  • View blog
  • Posts: 9,592
  • Joined: 08-June 10

Re: Php echo primary key

Posted 21 March 2013 - 03:58 AM

is your primary key an auto_increment? what is the setup (the CREATE TABLE statement) for the table?
Was This Post Helpful? 0
  • +
  • -

#3 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Php echo primary key

Posted 21 March 2013 - 10:50 AM

View PostDormilich, on 21 March 2013 - 03:58 AM, said:

is your primary key an auto_increment? what is the setup (the CREATE TABLE statement) for the table?


Yes it is,the create statement is from xampp i didnt write it.My description was bad..I want to get name of the CPrid..ex CPrid = 1 Name = "Mark" but is in another table
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Php echo primary key

Posted 21 March 2013 - 11:22 AM

Describe your schema (tables, foreign keys, etc).
Was This Post Helpful? 0
  • +
  • -

#5 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Php echo primary key

Posted 21 March 2013 - 11:34 AM

View PostJackOfAllTrades, on 21 March 2013 - 11:22 AM, said:

Describe your schema (tables, foreign keys, etc).



http://postimg.org/image/onpwj66ht/
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Php echo primary key

Posted 21 March 2013 - 12:00 PM

So you want to do a JOIN between customers and professions based on the CPrId in each table, at which point you can get the profession's description.
Was This Post Helpful? 1
  • +
  • -

#7 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Php echo primary key

Posted 21 March 2013 - 12:01 PM

View PostJackOfAllTrades, on 21 March 2013 - 12:00 PM, said:

So you want to do a JOIN between customers and professions based on the CPrId in each table, at which point you can get the profession's description.


exactly
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Php echo primary key

Posted 21 March 2013 - 12:06 PM

Well, read the manual and give it a try. That's HOW YOU LEARN.
Was This Post Helpful? 1
  • +
  • -

#9 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Php echo primary key

Posted 21 March 2013 - 12:15 PM

View PostJackOfAllTrades, on 21 March 2013 - 12:06 PM, said:

Well, read the manual and give it a try. That's HOW YOU LEARN.


What i would do is to create another query and after check if CPrid is the same to echo the description but i think thats a stupid way..there must be a faster way to do it
Was This Post Helpful? 0
  • +
  • -

#10 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Php echo primary key

Posted 21 March 2013 - 12:24 PM

View PostJackOfAllTrades, on 21 March 2013 - 12:06 PM, said:

Well, read the manual and give it a try. That's HOW YOU LEARN.


I have to use JOIN right? nevermind thanks for your time :whistling:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1