Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-19-2003, 04:02 PM   #1 (permalink)
dubsonic
Registered User
 
Join Date: May 2002
Posts: 10
dubsonic is on a distinguished road
Send a message via AIM to dubsonic
mysql query to populate an array

OK, what's wrong with this loop?
Code:
$result=mysql_query("SELECT *, UNIX_TIMESTAMP(time) AS newdate FROM albums WHERE username='$username' ORDER BY time DESC");
$num=mysql_numrows($result);
$thumb = array();

for($i=0;$i<$num;$i++){
	$id=mysql_result($result,$i,"id");
	$result2=mysql_query("SELECT * FROM images WHERE id='$id' ORDER BY pic_id LIMIT 1");
	$thumb[$i]=mysql_result($result2,$i,"thumb");
}
For some reason it only populates index=0 of the array.
dubsonic is offline   Reply With Quote
Old 06-19-2003, 04:29 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
Re: mysql query to populate an array

it's in the last loop .. you are calling on the "$i" result of $result2 .. since there is only 1 result, the only valid mysql_result would be 0. here ya go:
PHP Code:
<?
  $thumb
[$i]=mysql_result($result2,0,"thumb");
?>
__________________
Mike
sde is offline   Reply With Quote
Old 06-20-2003, 08:07 AM   #3 (permalink)
dubsonic
Registered User
 
Join Date: May 2002
Posts: 10
dubsonic is on a distinguished road
Send a message via AIM to dubsonic
Thanks sde, worked like a charm!!
dubsonic is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql nested query help! kitrak2004 Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 08-18-2004 06:33 AM
foreach() while() for() or new mysql query? nemesis PHP 6 06-10-2003 06:57 PM
and on to mysql .. sde Linux / BSD / OS X 2 01-18-2003 07:39 PM


All times are GMT -8. The time now is 01:17 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting