Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That little script can display both?? :-O?

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm

    @mysql_select_db($db,$link)

    Ive never seen the $link what the hell does that mean?

  • #6
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bah I dont understand much of this... Can you just plug the info in for me?

    Would help lots thanks.

  • #8
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    :-(

  • #9
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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

  • #10
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    Last edited by ASAAKI; 04-19-2003 at 08:32 PM.
    'If you don't stand for something, you'll fall for anything.'


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •