This is a discussion on "Very confusing mySQL array" within the PHP Forum section. This forum, and the thread "Very confusing mySQL array are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Very confusing mySQL array
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
Very confusing mySQL array
i'm pulling everything from my blog entries table:
Select * from blog_entries; this has 6 columns: id entry title timestamp rating cat (category) How would I go about doing this: <div class="blogentry"> <strong>Title from mysql</strong> - <span class="date">DATE</span> <span class="category">Category</span> <p>a bit of the entry, cut off after a while</p> <div class="rating"> rating </div> </div> for each row? it confuses me, i don't know how many arrays are in each array and stuff like that. Help appreciated, sorry if I didn't explain this properly.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|
|
#2
|
||||
|
||||
|
Re: Very confusing mySQL array
Hi Alex,
The preferred way is to loop through the results of the query with a while loop. eg.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
#3
|
||||
|
||||
|
Re: Very confusing mySQL array
unexpected string with the while loop unfortunately. I don't know why though :/
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#4
|
||||
|
||||
|
Re: Very confusing mySQL array
Woops, it works great thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#5
|
||||
|
||||
|
Re: Very confusing mySQL array
Could you explain the while statement please? I really don't get it.. and why doesn't the while loop have curly braces? This really confuses me. thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#6
|
||||
|
||||
|
Re: Very confusing mySQL array
No probs.
The mysql_fetch_array/row/array functions keep track of the last array index that was retrieved. This means that each time you call the function you get the next index of the array until there are none remaining when it will return false. Using this in a while loop means that when the statement evaluates to false (when no results remain) the conditional fails and the loop breaks. The reason why there are no curly braces is because there is only one statement in the loop. Curly braces aren't required for conditionals and loops unless you need to execute multiple statements. Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
#7
|
||||
|
||||
|
Re: Very confusing mySQL array
Oh thanks
How can I just loop through a certain number then? or have 10 entries per page?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#8
|
||||
|
||||
|
Re: Very confusing mySQL array
To loop through a certain number, the best thing would be to use a for loop
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
#9
|
||||
|
||||
|
Re: Very confusing mySQL array
Thanks Rakuli, I shall try to explain more though. (Sorry to ask so much).
how would I do it with the following: archives.php?s=1&e=10 archives.php?s=11&e=20 so, the first would show blogs 1 - 10 and the second would show 11 - 20 so on so forth?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#10
|
||||
|
||||
|
Re: Very confusing mySQL array
Hi alex,
Have a look at the code I wrote in This thread about paginationp It has an example of what you want to do.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
#11
|
||||
|
||||
|
Re: Very confusing mySQL array
Thanks Rakuli.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| checkbox[] array into mysql... OUT? | ppgpilot | PHP Forum | 1 | Mar 13th, 2008 20:37 |
| float issue (confusing) | danny322 | Web Page Design | 6 | Jan 10th, 2008 08:28 |
| Confusing Clock | adrix | Flash & Multimedia Forum | 5 | Aug 31st, 2006 14:26 |
| Uploading form-generated array to MySQL | masonbarge | PHP Forum | 1 | Jul 15th, 2006 17:46 |
| array unable to check another array so as to be displayed | Ozeona | Flash & Multimedia Forum | 1 | Aug 5th, 2005 10:26 |