Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-19-2003, 12:57 AM   PM User | #1
Jozh
New to the CF scene

 
Join Date: Apr 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jozh is an unknown quantity at this point
PHP/MYSQL quick help

Ok I got a databased named 'test_DB' and a table inside of that named 'Table1'. Inside of 'Table1' I have 2 feilds 'ID,Entry'.

Now on my php page How would I display a selected entry from its ID number which is from the ID column, and display it?


Thanks, Josh
Jozh is offline   Reply With Quote
Old 04-19-2003, 01:24 AM   PM User | #2
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
here, I barrowed this from the MYSQL forum...look harder next time for your answer...

$link = @mysql_pconnect($server, $user, $pwd)

or die("Could not connect: " . mysql_error());

@mysql_select_db($db,$link)

or die ("Could not select database." . mysql_error());

$sql_select = "select * from table ";

$result = mysql_query($sql_select, $link);

if ($result){

echo mysql_num_rows($result) ;

}

else {

echo ("Problem: " . mysql_error());

}


Jason
Jason is offline   Reply With Quote
Old 04-19-2003, 01:50 AM   PM User | #3
Jozh
New to the CF scene

 
Join Date: Apr 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jozh is an unknown quantity at this point
That little script can display both?? :-O?
Jozh is offline   Reply With Quote
Old 04-19-2003, 01:55 AM   PM User | #4
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
In your studying of MySQL you should have atleast learned about the SELECT statements, they are universal throught all dbs as far as I know. Now the SELECT statment you have here is SELECT * where the * reperesents all the information in the table...so if you look for a certain ID you would need something like a WHERE clause to say SELECT * WHERE ID==num or something. Not to positive on teh syntax but that will get the entire row where that ID has the same value as num...does that make sense?


Jason
Jason is offline   Reply With Quote
Old 04-19-2003, 01:55 AM   PM User | #5
Jozh
New to the CF scene

 
Join Date: Apr 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jozh is an unknown quantity at this point
hmm

@mysql_select_db($db,$link)

Ive never seen the $link what the hell does that mean?
Jozh is offline   Reply With Quote
Old 04-19-2003, 01:59 AM   PM User | #6
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
the $link is basically getting its information elsewhere, in PHP the $link will be a variable with the title link...in our case here its refering to $link = @mysql_pconnect($server, $user, $pwd) so it is making sure that you are connected to the MySQL server... make sense?

Jason
Jason is offline   Reply With Quote
Old 04-19-2003, 02:02 AM   PM User | #7
Jozh
New to the CF scene

 
Join Date: Apr 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jozh is an unknown quantity at this point
Bah I dont understand much of this... Can you just plug the info in for me?

Would help lots thanks.
Jozh is offline   Reply With Quote
Old 04-19-2003, 02:37 AM   PM User | #8
Jozh
New to the CF scene

 
Join Date: Apr 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jozh is an unknown quantity at this point
:-(
Jozh is offline   Reply With Quote
Old 04-19-2003, 08:28 PM   PM User | #9
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Quote:
Originally posted by Jozh
Bah I dont understand much of this... Can you just plug the info in for me?

Would help lots thanks.
It would seem that you don't wish to learn this in which case indicates to me that this could be a school homework assigment where you just want us to give you the answer. If that is the case we are done helping you.

It's not that difficult to understand. You should read through some basic SQL and PHP tutorials. There are plenty of threads that deal with both in these forums so you can use the search feature.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 04-19-2003, 08:29 PM   PM User | #10
ASAAKI
Regular Coder

 
Join Date: Jul 2002
Location: This little Earth.
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
ASAAKI is an unknown quantity at this point
just try this:
PHP Code:
//copied and pasted lots of this from phpdev's examples

$host="localhost";
$username="";
$password="";
$db="test_DB";
$link=mysql_connect($host,$username,$password)
or die (
"could not connect to database, please check that mysql is in fact running");
mysql_select_db($db);

// as Jason said, the (*) will just select all fields in a table. i've 
// selected them separately, don't ask me why 

$sql="SELECT ID,Entry FROM Table1"// the sql statement
$result=mysql_query($sql);   // actually executing the query here

//now print out all the IDs and Entries in each row using a loop
for($i=0$i<mysql_num_rows($result); $i++){
      
$row_array mysql_fetch_row($result); //fetch current row
      
echo("ID: {$row_array[0]}, Entry: {$row_array[1]} <br>");
      } 
if you can't get the code by reading it, i'll assume it means that you really haven't done much work with databases/programming. you should get hold of some tutorials.
have you downloaded phpdev? it's got lots of elementary examples to get u up and running.
visit www.php.net and read a bit of the manual, www.phpfreaks.com, www.mysql.com.
there are lots more php tutorials all over the web.



<edit>
oops.. a minute late... now if i'd seen spookster's reply first i wouldn't bother here.
</edit>
__________________
'If you don't stand for something, you'll fall for anything.'

Last edited by ASAAKI; 04-19-2003 at 08:32 PM..
ASAAKI is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:44 PM.


Advertisement
Log in to turn off these ads.