MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 25th, 2003, 01:45 AM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
going to the next row in a MySQL DB with PHP

Lets say I have table called stuff with 3 columns: Id, stuff, type.

id|Stuff |type|
------------------
1|stuff 1| 1 |
------------------
2|stuff 2| 2 |
------------------
3|stuff 3| 2 |
------------------
4|stuff 4| 1 |
------------------
5|stuff 5| 2 |
------------------
6|stuff 6| 1 |
------------------

now to display the whole table in reverse order all I need to do is
PHP Code:
 $query=mysql_query("SELECT*FROM stuff ORDER BY id DESC");
$createarray=mysql_fetch_array($query);
$loopid=$createarray['id'];
while(
$loopid=>1)
 {
   echo 
$createarray['stuff'];
   
$loopid--
 } 

That should show
"stuff 6stuff 5stuff 4stuff 3stuff 2stuff 1"

But I want it to only display those that are type "1" I know tp use the "WHERE" Clause to select the type but where I am not sure of what to do is how to get it to go to teh next row. I can't use "$loopid--" because it would count id's 5, 3 & 2. SO how can I get it to go to the next row thatmeets the "WHERE" criteria and actually skip over those that need ot be skipped
__________________
CHornJr
"One day I'll know what I am doing"
My Blog
Suanhacky Lodge #49
Rebel Squadrons

Reply With Quote
  #2  
Old June 25th, 2003, 03:46 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
You are almost there.

1. Put the where clause in your SQL statement.
2. Loop through the array only printing the stuff in the "stuff" column

Example:
PHP Code:
<pre>
<?
php

$stuff 
= array(
  array(
"id"=>6,
        
"stuff"=>"stuff 6",
        
"type"=>1
  
),
  array(
"id"=>4,
        
"stuff"=>"stuff 4",
        
"type"=>1
  
),
  array(
"id"=>1,
        
"stuff"=>"stuff 1",
        
"type"=>1
  
)
);

print_r($stuff);

print 
"<br>";

print 
"stuff 6stuff 5stuff 4stuff 3stuff 2stuff 1   (hard coded)";

print 
"<br>";

foreach (
$stuff as $item) {
  
$concat .= $item['stuff'];
}  

print 
$concat " (from array)";

?>
</pre> 


In the example I used an array... same thing.
Instead of a loop with foreach as I did, your loop will be a while loop:

PHP Code:
while ($item mysql_fetch_object($query) {
  
$concat .= $item['stuff'];
}

print 
$concat
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Last edited by laidbak : June 25th, 2003 at 03:50 AM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > going to the next row in a MySQL DB with PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT