Board index   FAQ   Search  
Register  Login
Board index php forum :: Database phpMyAdmin

Help a newbie get started.

How to use phpmyadmin.... phpmyadmin related arguments. Even phpMyAdmin issues

Moderators: macek, egami, gesf

Help a newbie get started.

Postby ScottDB » Sat May 21, 2011 7:25 am

Hi all. I'm just starting to learn php and sql on my own before I go to college for it. I am understanding how to write the sql and php codes easily enough. I understand how to create a database and post queeries to it and have them show up in the queery results. What I am not seeing anywhere in any of the tutorials is how to get the queeries to show up on a page.

example: If I use a simple php page with the opening and closing tags of php on it and insert the following code it should show up on the page in the browser correct?

$sql = "SELECT * FROM memb_info LIMIT 0, 30 ";

I cant get this to show on the page. Am I missing a step somewhere? I've also tried it with calling the database as well using
use database; above that in the tags.
User avatar
ScottDB
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sat May 21, 2011 7:21 am

Re: Help a newbie get started.

Postby johnj » Sat May 21, 2011 8:26 am

You need to do the following steps:

a).Establish a connection with the database server
b).Then, run the sql you have created
c).Pull the results returned and display it

Here is an example:
http://phillipnb.wordpress.com/2010/12/
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Help a newbie get started.

Postby ScottDB » Sat May 21, 2011 4:58 pm

Thanks for the response. I am trying to do this with my hosting account cpanel/phpmyadmin so I assume that is what you are talking about in (a).
I can make a data base and tables. I can run sql queries and get the results. exsample - If I run this querey "SELECT * FROM memb_info LIMIT 0, 30 " I get the table of results to show up in the phpmyadmin. What would I use to get it to show on the web page.

After looking at your example in the link I take it I should use the top part of the code that you have there up to the line "While ($myWidget = mysql_fetch_object($myResult))". Inserting my info of course. Is this correct? The only value I couldn't get for those is the database_Server. Will ask my host for this.

Edited: I tried the code that you had on the example you linked to in the post and got some errors untill I figured out I used the wrong password. Once I used the correct password I am not getting anything showing for results. Here is what I have

<?php
define( "DATABASE_SERVER", "localhost" );
define( "DATABASE_USERNAME", "xxxx" );
define( "DATABASE_PASSWORD", "xxxxxx" );
define( "DATABASE_NAME", "xxxxxx" );

$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
mysql_select_db( DATABASE_NAME );

$sqlQuery = "SELECT * FROM memb_info LIMIT 0, 30 ";
$myResult = mysql_query($sqlQuery);
$myReturn = "";

?>
User avatar
ScottDB
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sat May 21, 2011 7:21 am

Re: Help a newbie get started.

Postby johnj » Sun May 22, 2011 6:30 am

Your code has steps a and b. Now you need to do step c. Here is a sample code:
Code: Select all

while 
($row = mysql_fetch_assoc($myResult)) {
    echo "<br/>".$row["userid"];
    echo "<br/>".$row["firstname"];
    echo "<br/>".$row["lastname"];
    echo 
"<br/>";
}
 


I do not know what fields your table 'memb_info' has. userid,firstname and lastname are the fields, you need to change them. echo does the display...so, you should now be able to see the data on a web page
Last edited by johnj on Sun May 22, 2011 6:36 am, edited 1 time in total.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Help a newbie get started.

Postby johnj » Sun May 22, 2011 6:35 am

I am trying to do this with my hosting account cpanel/phpmyadmin so I assume that is what you are talking about in (a).


No, I am talking about what you did at the top of the code,i.e. telling php where your database server is, what user name and password to use to login, the database name ...upto to the line mysql_connect().

The rest, you have already figured that out.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Help a newbie get started.

Postby ScottDB » Sun May 22, 2011 8:40 pm

Hey thanks for the code. I asked the same question in another forum and got basicly the same code from there as well. I'm starting to understand this a lot better now. I looked at 3 different tutorial sites and never saw this as well as googling it. You would think if you are going to have a tutorial that this should be covered as one of the first things you learn so that you can check your work as you learn.

Now I just have to figure out how to get the results to show each value returned in their own html table on a page.

I got a lot to learn but I enjoy it.
User avatar
ScottDB
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sat May 21, 2011 7:21 am


Return to phpMyAdmin

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.