NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP loop

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-26-2006, 10:29 AM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




PHP loop


Hey, Need a little help. Basically the following script should be checking the users credits and if they have more than 1, then display their link....But it doesn't. The script just takes forever to load. Then again I'm with Dreamhost and they're...well...awful.

PHP Code:
$o=0;
while (
$o<1)
{
$res mysql_query ("SELECT * FROM sites WHERE active='1' ORDER BY rand() LIMIT 1");
while (
$row mysql_fetch_array($res)) 

$id $row['id'];
$member $row['member'];
$url stripslashes($row['url']);
}



$res mysql_query ("SELECT * FROM users WHERE id='$member'");
????: NamePros.com http://www.namepros.com/programming/171485-php-loop.html
while (
$row mysql_fetch_array($res)) 

$credits $row['credits'];
}

if (
$credits>=1) {$o "1"; }
else {
$o "0"; }
}

$credits--;

$res mysql_query ("UPDATE users SET credits='$credits' WHERE id='$member'"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=171485
Encenta.com is offline  
Old 02-26-2006, 10:59 AM   #2 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
The only thing I see missing is to end your first loop. Try adding a } to the end of it.
Dan is offline  
Old 02-26-2006, 11:42 AM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,963
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Not sure about your purpose but you could do that in SQL

Fetch one random record:
????: NamePros.com http://www.namepros.com/showthread.php?t=171485
PHP Code:
SELECT FROM sites WHERE active='1' and credits 1 ORDER BY rand() LIMIT 1 
BTW why do you use quotes for active and credits fields ? These fields are numeric right ?

For the updates you could do that in one shot too... using SQL again. I don't see the purpose of the PHP code here.
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is online now  
Old 02-26-2006, 12:56 PM THREAD STARTER               #4 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




well the active row is in the 'sites' table and the credits row is in the 'users' table
Encenta.com is offline  
Old 02-26-2006, 01:04 PM   #5 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,963
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
You can do a join between the two tables:
PHP Code:
SELECT field1field2...
FROM sites
INNER JOIN users
ON sites
.id=users.id

WHERE sites
.active='1'
????: NamePros.com http://www.namepros.com/showthread.php?t=171485
AND users.credits 
In this example I assume the ID field is the one to match the two tables together.
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is online now  
Old 02-26-2006, 02:15 PM THREAD STARTER               #6 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thanks but how do I use that code to choose a random row?
Encenta.com is offline  
Old 02-26-2006, 02:50 PM   #7 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,963
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Well you just add this at the end:

ORDER BY RAND() LIMIT 1

ORDER BY RAND() means sort in random order and LIMIT 1 means limit the query to 1 record.
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is online now  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Great Scripts for Sale With Resale Rights! Zeeble Scripts For Sale 20 01-04-2006 01:39 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM

 
All times are GMT -7. The time now is 02:10 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger