Jump to content

[SOLVED] Problems with SELECT


zamp0e

Recommended Posts

I'm having huge problems learning the sql syntax for INSERT, and how to properly use it to get an output in the browser.

 

For far too long now I have tried to simply print out the first 5 rows of my database, I have searched the web for tutorials on how to do this, and they all say the same; something like this:

 

SELECT * FROM table_name

 

That's all I've found, I know I have to declare it and stuff like that but I just don't know how.

 

So the question is, How do I get my browser to print out the 5 first lines of my database ?

Link to comment
Share on other sites

First 5 records according to what?  (id, date, etc...)

 

It would look something like:

 

SELECT * FROM table LIMIT 5

 

(You will need ORDER BY if you want to get the first/last 5 according to a specific column)

Link to comment
Share on other sites

I'd like to print out 5 rows where the ID is (1,2,3,4,5)

 

The thing I tried was something like:

SELECT name FROM iqtable WHERE ID=1
echo "$name"
SELECT name FROM iqtable WHERE ID=2
echo "$name"
SELECT name FROM iqtable WHERE ID=3
echo "$name"
SELECT name FROM iqtable WHERE ID=4
echo "$name"
SELECT name FROM iqtable WHERE ID=5
echo "$name"

 

Obviously, this is nowhere near right, as it's not working, and just looks plain stupid.

Link to comment
Share on other sites

There's examples in the manual - mysql_query.

 

I guess I assumed the value of ID wouldn't change. As in, a row with ID 10 wouldn't be before a row with ID 5.

 

Maq - I think the column is ID, not id.

 

Ah yes, 'ID' not 'id'.  ;)

Link to comment
Share on other sites

Thanks

 

NP, the query should be the hardest part, and you've already got that done.  If you have any questions, I would probably create a new thread in the 'PHP Help' section.  So if the query is solved, please mark as so.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.