Page 10 of 11
Re: Newb advice
Posted: Sun Nov 01, 2009 9:31 am
by MiniMonty
HI all,
been away for a while earning a living but I'm back and determined to finish this thing !
So...
I took the advice and built a DB to hold all the pictures. It looks like this:
I got the upload page working so that images are uploaded to the users "images" directory and inserted into the DB
with a reference to the chosen gallery, a filepath and a date added.
So now I need build galleries that can display all the pictures uploaded by one member,
or which have been uploaded to a specific gallery (portraits, landscapes etc) and I'm not sure how to go forward.
The logic in my head says I need something like this:
Code: Select all
$sql = mysql_query("SELECT * FROM pictures WHERE UID='$id'");
(because users are identified by $id) followed by a loop of some kind but no matter how often I read the online
php manual I just can't get my head round it !
All and any advice much appreciated
Best wishes
Monty
Re: Newb advice
Posted: Sun Nov 01, 2009 11:30 am
by jackpf
You'll the need something like:
Code: Select all
while($fetch = mysql_fetch_array($sql))
{
//code here
}
to loop through each picture.
Re: Newb advice
Posted: Sun Nov 01, 2009 1:46 pm
by MiniMonty
AHA !!
so this:
Code: Select all
echo "<table>";
while (($row = mysql_fetch_assoc($sql)) !== false) {
echo "<tr>";
echo "<td>", $row["dirpath"], "</td>";
echo "</tr>";
}
echo "</table>";
gives me a list of one particular users images as paths to the images (which is cool).
How can I convert this to give me a comma delimited array that I can give to Flash ?
i.e. /members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg
Best wishes
Monty
Re: Newb advice
Posted: Sun Nov 01, 2009 3:56 pm
by jackpf
Pretty much. Although you don't need the !== false bit, since while() loops terminate on false anyway.
And just append to an array.
Code: Select all
$array = array();
while($fetch = mysql_fetch_array($sql))
{
$array[] = $fetch;
}
Re: Newb advice
Posted: Sun Nov 01, 2009 4:16 pm
by MiniMonty
Cool - didn't realise it would terminate on false - php is a lot more forgiving (or perhaps just
more intuitive) than ActionScript !
Re: Newb advice
Posted: Sun Nov 01, 2009 5:01 pm
by jackpf
Im pretty sure thats how it works in all languages....but meh

Re: Newb advice
Posted: Mon Nov 02, 2009 9:06 am
by MiniMonty
I'm missing something...
After my query:
Code: Select all
$sql = mysql_query("SELECT * FROM pictures WHERE UID='$id'");
this will give me a list of images in the db attached to the member:
Code: Select all
echo "<table>";
while (($row = mysql_fetch_assoc($sql)) !== false) {
echo "<tr>";
echo "<td>", $row["dirpath"], "</td>";
echo "</tr>";
}
echo "</table>";
this will actually show the images in the browser:
Code: Select all
while ($row = mysql_fetch_assoc($sql)) {
echo '<img src="', $row['dirpath'] ,'"/><br />';
}
but when I use this:
Code: Select all
$array = array();
while($fetch = mysql_fetch_array($sql))
{
$array[] = $fetch;
}
echo $array;
I just get "Array" printed onto the browser.
What am I missing to give me an array like this: /members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg
Once I have that I can feed it to Flash and display the images in a cool interface.
Best wishes
Monty
Re: Newb advice
Posted: Mon Nov 02, 2009 9:28 am
by jackpf
Umm, because it's an array. Try using print_r() or var_dump() instead.
Re: Newb advice
Posted: Mon Nov 02, 2009 9:36 am
by Mirge
Haven't we gone over this already? Like at the very beginning of this thread? I'm getting the feeling you're not learning anything/much... you should start experimenting more on your own and doing actual research. When you put work into it instead of just asking for answers.. you tend to retain knowledge better.
Re: Newb advice
Posted: Mon Nov 02, 2009 9:53 am
by jackpf
I agree
Didn't realise this had already been covered...
Re: Newb advice
Posted: Mon Nov 02, 2009 10:19 am
by MiniMonty
Doh !
I am learning - but It's a bit like learning to remember the difference between b and d and p when you're five !
Re: Newb advice
Posted: Mon Nov 02, 2009 11:15 am
by MiniMonty
So just to let you know that I'm paying attention and (albeit slowly) learning this is how
I solved it. I need a dead simple array (with no extras or details) for flash to show the pictures.
It has to start with "&blahblah=" for Flash to recognise it as a literal string array.
And here's what I came up with:
Code: Select all
$flashVar="";
while (($row = mysql_fetch_assoc($sql)) !== false) {
$imagelist= $row["dirpath"]. ",";
$flashVar=$flashVar.$imagelist;
}
echo ("&picsForFlash=" .$flashVar);
Best wishes
Monty
Re: Newb advice
Posted: Mon Nov 02, 2009 11:19 am
by Mirge
MiniMonty wrote:So just to let you know that I'm paying attention and (albeit slowly) learning this is how
I solved it. I need a dead simple array (with no extras or details) for flash to show the pictures.
It has to start with "&blahblah=" for Flash to recognise it as a literal string array.
And here's what I came up with:
Code: Select all
$flashVar="";
while (($row = mysql_fetch_assoc($sql)) !== false) {
$imagelist= $row["dirpath"]. ",";
$flashVar=$flashVar.$imagelist;
}
echo ("&picsForFlash=" .$flashVar);
Best wishes
Monty
Very good : ).
Now that you've figured it out on your own, you will very likely remember how to do it again in the future, much quicker.
Re: Newb advice
Posted: Sat Nov 07, 2009 3:44 pm
by MiniMonty
Evening all...
Here's a question about server response time.
At present I'm using this query:
Code: Select all
$sql = mysql_query("SELECT * FROM pictures WHERE UID='$id'");
coupled with this:
Code: Select all
//WRITE A STRING (ARRAY) THAT FLASH CAN READ
$clever="";
// LOOP THROUGH THE DB AND MAKE A LIST
while (($row = mysql_fetch_assoc($sql)) !== false) {
$imagelist= $row["dirpath"]. ",";
$clever=$clever.$imagelist;
}
//print ("&galpic=" .$clever);
// NOW COUNT THE COMMAS IN THE STRING TO GIVE AN "allpics" VALUE TO FLASH.
$temp_string=$clever;
$num_of_pics= substr_count($temp_string,",");
and then passing all the data to Flash like this (just for anyone who's interested in how to pass php variables to a Flash front end)
Code: Select all
<embed src="memDBgallery.swf" FlashVars="galpic=<? echo "$clever";?> &allpics=<?php echo "$num_of_pics";?>"
So my question is this - at present there are only a few pictures in the db and any one user is not likely
to upload more than say 50 images in the lifetime of their membership. But, over time, the galleries they upload
to (portraits, Landscapes) etc., will become very big indeed. So if I used a query like this:
Code: Select all
$sql = mysql_query("SELECT * FROM pictures WHERE gallery='landscapes'");
and the gallery contained 30,000 images would the server response time or the processing by php be significantly slow ?
(I know it must vary from server to server but assume a basic Linux shared box via an OK hosting service).
Are there any limits I should be aware of when putting this together in terms of a maximum number of elements
in an array or maximum bytes "to and fro" that sql or php can handle ?
Best wishes
Monty
Re: Newb advice
Posted: Sun Nov 08, 2009 6:23 am
by jackpf
You're only limited by your server's hardware.
I doubt one linear query will take too long. But, if you're really worried, you should probably only be selecting `dirpath`, rather than all rows, since that's all you're using...