Page 1 of 1

image display help!!

Posted: Tue Jun 03, 2008 6:23 am
by kanchan
can we sort the image displaying with their height and width?
this is my code

Code: Select all

<?
include 'connect.php';
$thumb_loc="images";
$query = mysql_query("SELECT * FROM images order by id"); 
 
while($row = mysql_fetch_array($query)){
$id = $row["id"];
$img_name=$row["name"];
$img_thumb = $row["thumb"];
$cap= $row["caption"];
$imginfo = getimagesize("$thumb_loc$thumb");
 
$src=$thumb_loc/$img_thumb;
 
echo $src;
}
?>
now i wanna display those images; the images having width greater first and one line break and then those images having height greater...

Is this possible to make??

can you guys please help me out??

Re: image display help!!

Posted: Tue Jun 03, 2008 7:06 am
by vargadanis
Hi!

It is very well possible but you need to know a couple of things.
First of all, I would create a tmp array for the with and height and append it to the row array:

Code: Select all

$tmp = array("dimensions" => getimagesize("img.jog")); // i ve never done it this way, put it could work...
array_push($row, $tmp);
With this you would have added the height and width of the images to the row array. From this point on zou only need to arrange the items based on their height or width. One of the best way of doing it is using bubble sort: http://en.wikipedia.org/wiki/Bubble_sort
Or use one of the built in functions: http://hu.php.net/manual/en/function.usort.php

Peace!

Re: image display help!!

Posted: Tue Jun 03, 2008 1:56 pm
by kanchan
:? :? :?
as i am not so perfect in php coding...

i am not getting what you are saying... SORRY

do u have any codes for this?
please help me....... :oops: :oops: :oops:

Re: image display help!!

Posted: Wed Jun 04, 2008 7:59 am
by kanchan
is there any HELP for me?? :( :( :(

Re: image display help!!

Posted: Wed Jun 04, 2008 8:19 am
by Frozenlight777
maybe try this in the loop.

echo "<img src=" . $src . "/>";

Re: image display help!!

Posted: Wed Jun 04, 2008 10:28 am
by kanchan
:banghead: :banghead: :banghead:

Re: image display help!!

Posted: Wed Jun 04, 2008 10:41 am
by vargadanis
Relax... It's OK if you are not that good at PHP as of now.

Here is an example for what I meant:

Code: Select all

<?
include 'connect.php';
$thumb_loc="images";
$query = mysql_query("SELECT * FROM images order by id");
/**
* EXTRA
*/
$list_of_pics = array(); // empty array
 
while($row = mysql_fetch_array($query)){
  $id = $row["id"];
  $img_name=$row["name"];
  $img_thumb = $row["thumb"];
  $cap= $row["caption"];
  $imginfo = getimagesize($thumb_loc . $thumb); //you do not need "" signes if u use vars
  /**
  *  EXTRA
  */
  $tmp = array();  //push is appending
  array_push($tmp, $imginfo);  // push info on sizes into tmp array
  array_push($row, $tmp);  // push tmp array to row array
  array_push($list_of_pics, $row);  // push row array into  list of pics array
  $src=$thumb_loc/$img_thumb;
 
  echo $src;
}
 
/**
*EXTRA for debugging...
*/
print "<pre>";
print_r($list_of_pics);
print "</pre>";
?>
supposingly you have all the pics with size info in an array (list_of_pics). You only need to sort them now..

Re: image display help!!

Posted: Thu Jun 05, 2008 11:21 am
by kanchan
:? :? :?

i copy and pasted that code but it shows error something like this :
Warning: array_push(): First argument should be an array in view.php

and you told me to sort that but how to do that (list_of_pics)??
help me!!!

Re: image display help!!

Posted: Fri Jun 06, 2008 1:13 am
by RobertGonzalez
Kanchan, can you please calm your requests for help down. We get that your requests are important, but posting Help me!!!! over and over is going to get your posts overlooked.

Help us help you by being patient for help. We are all volunteers and we get to helping others as we get time. Thanks.

Re: image display help!!

Posted: Fri Jun 06, 2008 8:12 am
by vargadanis
Everah wrote:Kanchan, can you please calm your requests for help down. We get that your requests are important, but posting Help me!!!! over and over is going to get your posts overlooked.

Help us help you by being patient for help. We are all volunteers and we get to helping others as we get time. Thanks.
Thank you Everah...

Ok... Kanchan... You are new to PHP, I understand that. You must however understand that there are a lot of things that you do not know about the language. Try to be patient with yourself. I know that it can be very frustrating that you cannot do everything that you want to do. Here is a strategy I followed over the years: take small steps. If you do not understand part of the code, try to think of an application which could use similar code. Eg: to practice the array push, try to create an array of 3 variables, that the user gives you in a form. And then when he hits submit, print them out. With this you will understand how array_push works. If you get a similar error or warning code, you will know next time why it is.
Another thing: I started off using Notepad for coding. It helps a lot if you use an editor which can do highlighting at least. Such IDEs for windows are: Notepad++, Dreamweaver, PHPEclipse, PDT for Eclipse, NetBeans for PHP. For linux: pretty much all of them, from mcedit through gedit to vim. And of course there are other professional IDEs as well. I use NetBeans.

To learn what each of the errors mean, the fastest way is to use google. Now it has a scholar.google.com website as well, which will give you some extra hits to it. Very Very Useful... You might find an answer faster than asking on forums as we all are people and need time to sleep. Google does not.

I did my best to help you. You were just angry with me. I am affraid I cannot help you in this issue any more.

Re: image display help!!

Posted: Fri Jun 06, 2008 11:02 am
by kanchan
Thank You guys... :oops: :oops: :oops: