We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
MySQL question
Topic Started: Jun 3 2005, 06:06 AM (647 Views)
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Ok, lets say I use
Code:
 
$items_result = mysql_query("SELECT * FROM items ");
$number_of_items = mysql_num_rows($items_result);

Now, lets say I get 20 results.
And I want to display number 11 trough15.
Would doing this:
Code:
 

for($q=0;$q<=10;$q++)
{
$item = mysql_fetch_row($items_result);
}
for($w=11;$w<=15$w++)
{
$item = mysql_fetch_row($items_result);
echo 'whatever I wanna echo about the item'
}

Would that do what I want?

And, could I use
Code:
 

$item = mysql_fetch_row($items_result);
echo $item[id] . 'is the ID of the item';

(The name of the id col in the table is id)
Of would I have to do
Code:
 

$item = mysql_fetch_row($items_result);
echo $item[0] . 'is the ID of the item';

(of whatever the the number of the col would be)


*Qj wonders if this made any sence :unsure:
Well, if not, just tell me :P


Damn, *Qj made typos :o
(Big typos to :$ )


EDIT:
Sani helped me with the first one.
(he told me to use
Code:
 
mysql_query("SELECT * FROM items LIMIT 11,15");
)
Thanks for that :)

Offline Profile Quote Post Goto Top
 
Fire Pheonix (PM)
Member Avatar
Too much pressure!
[ *  *  *  * ]
Qj
June 3, 2005 05:06 AM

And, could I use
Code:
 

$item = mysql_fetch_row($items_result);
echo $item[id] . 'is the ID of the item';

(The name of the id col in the table is id)
Of would I have to do
Code:
 

$item = mysql_fetch_row($items_result);
echo $item[0] . 'is the ID of the item';

(of whatever the the number of the col would be)

You would have to use $item['id'] and you could use it for all the other variables including say, $item['title'] (as long as the row, 'title' , was in the mySQL database)
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
Doesn't mysql_fetch_row() only return it as numeric based?

to do it with the column headings, you'd have to do:

mysql_fetch_assoc(), or mysql_fetch_array($result,MYSQL_ASSOC)

but mysql_fetch_array() is like this:

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo $row['bob'];
}
Offline Profile Quote Post Goto Top
 
Gornakle
Member
[ *  *  *  *  * ]
mysql_fetch_array(), by default, gets both number indices and associative indices (as in, the column name). In your case, using mysql_fetch_assoc() would probably be better.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Rory
June 4, 2005 12:33 PM
but mysql_fetch_array() is like this:

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo $row['bob'];
}

I know, just needed a quick example :P

Anyway, thanks for the help.

So if I'm getting this right, I can just turn mysql_fetch_array() into mysql_fetch_assoc and it will work?
Yay :)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply