Creating a PHP interface that hits a mySQL backend

Discussion in 'PHP' started by MikeNX, Mar 13, 2008.

  1. #1
    I have a database that contains names, places, and several other fields.

    ID - University Name - Group Name - Website - Email


    Now I would like to have a way so that I can choose 'University Name' and have it display all the groups that are a part of that university. Or vice versa. Thats part 1.

    Part 2 coming soon.

    Thank you for all your help, I really appreciate it.
     
    MikeNX, Mar 13, 2008 IP
  2. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    http://www.php-mysql-tutorial.com/ or http://www.tizag.com/mysqlTutorial/index.php

    You will have something like this

    
    
    <?php
    $dbhost = 'localhost';  //fill in your mysql host
    $dbuser = 'root';  //fill in your username
    $dbpass = 'password'; //fill in your password
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
    
    $dbname = 'the_name_of_your_database';  //fill in the database name
    mysql_select_db($dbname);
    
    //connection to your db is made
    //now you need to select the table and select the info you need
    
    
    
    ?>
    
    Code (markup):
    Take a look at the tutorials..it's not that hard and start playing with it
     
    Edynas, Mar 13, 2008 IP
  3. MikeNX

    MikeNX Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Awesome I'm starting to understand a little bit.

    I'm going to want to specify a read only username correct?

    What permissions should just a read only username need? I'm using phpmyadmin for most of the work.
     
    MikeNX, Mar 13, 2008 IP
  4. pondlife

    pondlife Peon

    Messages:
    898
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just give the username that's going to be in public web pages the minimal permissions to function - mine have read and add access and that's it... (you can configure this from cpanel - which is easier than having to code a user table with specific permissions...)

    To answer one of your questions in order to select via University you'll need an SQL select statement like this:

    select * from table where university="'.$uni.'"

    where $uni is the variable that's populated by your pages drop-down list (or whatever input mechanism you're chosing...

    the select statement would then need to be wrapped in PHP:

    mysql_query=("select * from table where university="'.$uni.'" ");

    Check my syntax tho as I could be wrong! ;)
     
    pondlife, Mar 13, 2008 IP
  5. MikeNX

    MikeNX Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey all


    I've been trying to format my PHP output on my script. So far I can do three things... Bold Italic Underline using b i u but thats it.. I have no clue how to use color or font or anything.

    Any ideas? It would be ideal to be able to have no border.. which I know how to do.. and have alternating font/text backing color for each row.

    Here's my script:
    
    <?php
      include('dbconnect.php');
    ?><style type="text/css">
    <!--
    body {
    
    }
    -->
    </style>
    ...
    
    <?php
     // Get all the data from the "Groups" table
    $result = mysql_query("SELECT * FROM Groups") 
    or die(mysql_error());  
    
    echo "<table border='1'>";
    echo "<tr> <th><b>University</b></th> <th>Group</th> <th>State</th> <th>Zip Code</th> <th>Website</th> <th>Email</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    	// Print out the contents of each row into a table
    	echo "<tr><td>"; 
    	echo $row['University_Name'];
    	echo "</td><td>"; 
    	echo $row['Group_Name'];
    	echo "</td><td>"; 
    	echo $row['State'];
    	echo "</td><td>"; 
    	echo $row['Zipcode'];
    	echo "</td><td>"; 
    	echo $row['Website'];
    	echo "</td><td>"; 
    	echo $row['Email'];
            echo "</td></tr>";
    } 
    
    echo "</table>";
    ?>
    
    Code (markup):
     
    MikeNX, Mar 19, 2008 IP