Page 1 of 1

Outputting a mysql_fetch_array result

Posted: Tue Apr 27, 2010 11:49 am
by jwburnside
Hey everyone, I am trying to display the result set of an array that I got from mysql_fetch_array, like this:

while($imageinfo_array = mysql_fetch_array( $imageinfo_query ))

<?php echo $imageinfo_array['IMAGE_NAME'] ; ?>
<?php echo $imageinfo_array['CATEGORY_TYPE'] ; ?>

etc.

But there is sometimes more than one CATEGORY_TYPE associated with an IMAGE_FILE. I am just looking to print out the image name and then the corresponding categories associated with them, without reprinting the image again.

I'm pretty sure this is common, but I've been at a loss as to an easy way to do it.

Thanks,

JW

Re: Outputting a mysql_fetch_array result

Posted: Tue Apr 27, 2010 1:33 pm
by jraede
What does your query look like?

Re: Outputting a mysql_fetch_array result

Posted: Tue Apr 27, 2010 2:09 pm
by a94060
jwburnside wrote:Hey everyone, I am trying to display the result set of an array that I got from mysql_fetch_array, like this:

Code: Select all

while($imageinfo_array = mysql_fetch_array( $imageinfo_query ))

<?php echo $imageinfo_array['IMAGE_NAME'] ; ?>
<?php echo $imageinfo_array['CATEGORY_TYPE'] ; ?>
etc.

But there is sometimes more than one CATEGORY_TYPE associated with an IMAGE_FILE. I am just looking to print out the image name and then the corresponding categories associated with them, without reprinting the image again.

I'm pretty sure this is common, but I've been at a loss as to an easy way to do it.

Thanks,

JW
I'm guessing your query must be something like

Code: Select all

SELECT * FROM table WHERE image_name='image name' 
If that is so then you just need to keep doing

Code: Select all

<?php echo $imageinfo_array['CATEGORY_TYPE'] ; ?>
for each additonal category.

You may want to first run a query to select all the distinct image names, store them into an array, and then use a foreach statement to run a mysql query for each individual picture to select all its categories. The other way I would recommend would be to maybe make a category column in the table, and then store all the categories using a comma between each. Then you could just get the value of category, and use explode to break that up individually if you need to.