Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query database on page load? 1

Status
Not open for further replies.

xWastedMindx

Technical User
Joined
Sep 3, 2002
Messages
67
Location
US
I have a mySQL database, using PHP of course. I have my data, and I'd like it to load as soon as the main page loads displaying on the page.

I'm thinking I need to use the onLoad statement and use PHP_SELF with a query to the database?
I'm probably wrong though.

If I am, how would I go about doing this?

I've looked around and searched and couldn't find anything on this.

Thanks in advance.
Kenny

 
You're right. PHP runs on the server. Performing an onload won't work.

With PHP, you point your browser to the PHP script, and write that script to produce the entire page, including the data from your database.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Well.. yes, I already can do this.. Sort of.

What I have so far, it displays when I press a button to query and retrieve/display the database.

But how would I go about doing this as the initial index.php page loads?

I don't want to press a link and/or button for it to work.
I just want it to display when I visit the page.

I'm still kind of new, but learning rather quickly.

-Kenny

 
Ok.. ok. I can see you're a bit confused as to what exactly I'm talking about. So I'll try to explain.

I have a Webpage, HTML forms and PHP. It's inputing my DVD collection for my own personal use. I already have the input(INSERT) section completed (dvdID, dvdName, and dvdPrice; I'll probably add more later but I'm just trying to get it to work the way I want it, first).

I can goto Webmin and see my data, and I just recently added a button with a query running behind it to display my DB on another page.

But instead of pressing the button to display my data on the other page, I want it to load directly onto the screen as soon I visit the first page.
From there, I can use the form and add more data to the DB if I feel like it. Possibly even auto-refreshing to display the new data that was just inputed.

So from all this, my initial question was -- How can I display my database from the beginning, without pressing a button or link to display my data? I just want it to retrieve my data as soon as I visit it.

I hope you can understand that now. That's as best a summary as you're going to get ;-)

 
Scratch all that. I think I just found a way to do it myself.

What I had was the page as a standalone.
What I _CAN_ do, is set up a link from my regular Website, therefore adding the query to where it'll pull the data as soon as I visit the main page of my DVD collection page(DB).

But that means I'll have to set up extra security measures on my database... because it'll be accessible through my regular Website as well. But then again, I could just through a cookie script in there, and use some Authentication. :-D

Thanks for your help. Although it'll be a little more work than expected.. I found the way. Unless you have another way to do it.. possibly easier?

 
If you are calling the page directly (ie.. you can simply put the PHP code to query the db in, then build the output all as one page. You would just need to integrate the code that your button calls into the main page and make sure it has a .php extension. Then when you called the query would execute as part of the PHP preprocess, and your HTML would display afterwards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top