Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Array to create list with image problem
Old 12-22-2010, 12:18 PM Array to create list with image problem
Skilled Talker

Posts: 50
Trades: 0
The code below generates the following

PHP Code:
$sectlist "";
$sql "SELECT sect_name, sect_image, art_title, art_image1 FROM sections, artSections, articles WHERE art_approved = 1 AND art_archived = 0 AND sect_id = as_section AND as_article = art_id AND sect_id != 2";
$result1 mysql_query($sql);
$num_rows mysql_num_rows($result1);
$combinedResults = array();

while(
$result mysql_fetch_array($result1)) {  
    
$combinedResults[$result['sect_name']][] = array(
      
'title' => $result['art_title'],
      
'img' => $result['art_image1'],
    );
}

$sectlist .= "<ul>";
// now loop through the combined results
foreach(array_keys($combinedResults) as $groupKey) {
    
$sectlist .= "<li>".$groupKeyPHP_EOL//Need image here
    
$sectlist .= "<ul>"PHP_EOL;
    foreach(
$combinedResults[$groupKey] as $item) {
        
$sectlist .= "<li>".$item['title']." <img src='images/uploaded/" $item['img'] . "' width='20px'></li>"PHP_EOL;
    }
    
$sectlist .= "</ul>"PHP_EOL;
    
$sectlist .= "</li>"PHP_EOL;
}
$sectlist.= "</ul>";  
//End section list 
I'm having a problem getting an image next to the main bullet points. Could someone point me in the right direction.

Cheers

Wayne.
HullBorn is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-22-2010, 01:03 PM Re: Array to create list with image problem
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Can't you just add the image before the nested list?
PHP Code:
$sectlist .= "<li>" $groupKey '<img src="someimage" />' PHP_EOL
If the problem you are having is with styling the list and not actually updating the PHP code you might want to post the output of that code in the CSS forum.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 12-22-2010 at 01:05 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-22-2010, 06:31 PM Re: Array to create list with image problem
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
or were you hoping to turn the bullet into the image?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 12-23-2010, 04:12 AM Re: Array to create list with image problem
Skilled Talker

Posts: 50
Trades: 0
NullPointer, The image for the section is pulled from the database. I can put the image next to the section name but it brings in the same image (Dining Furniture)

Set the image here
PHP Code:
while($result mysql_fetch_array($result1)) {  
    
$combinedResults[$result['sect_name']][] = array(
      
'title' => $result['art_title'],
      
'img' => $result['art_image1'],
    );
    
$img $result['sect_image']; //Set image here
    

Used the image here
PHP Code:
$sectlist .= "<li>".$groupKey." <img src='images/uploaded/$img' width='30px'></li>"PHP_EOL
HullBorn is online now
Reply With Quote
View Public Profile
 
Old 12-23-2010, 04:24 AM Re: Array to create list with image problem
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Calling print_r on $combinedResults might shed some light on where the image you are looking for is stored.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-23-2010, 05:06 AM Re: Array to create list with image problem
Skilled Talker

Posts: 50
Trades: 0
I've called print_r $combinedResults and the section images are not showing
HTML Code:
Array
(
    [Chairs, Sofas &amp; Footstools] => Array
        (
            [0] => Array
                (
                    [title] => Seville High Back Chair
                    [img] => 2010_09_28_11_53_46_seville-hb-chair_sm.jpg
                )

            [1] => Array
                (
                    [title] => Seville Standard Back Chair
                    [img] => 2010_09_28_11_54_08_seville-sb-chair_sm.jpg
                )

            [2] => Array
                (
                    [title] => Seville Low Back Chair
                    [img] => 2010_09_28_11_54_27_seville-lb-chair_sm.jpg
                )

            [3] => Array
                (
                    [title] => Seville Standard Back Sofa
                    [img] => 2010_09_28_11_54_41_seville-sb-sofa_sm.jpg
                )

            [4] => Array
                (
                    [title] => Ontario Wing Chair
                    [img] => 2010_09_28_13_47_56_ontario-wing-chair-sm.jpg
                )

            [5] => Array
                (
                    [title] => Ontario High Back Chair
                    [img] => 2010_09_28_13_48_13_ontario-hb-chair-sm.jpg
                )

        )

    [Dining Furniture] => Array
        (
            [0] => Array
                (
                    [title] => Barcelona Dining Set
                    [img] => 2010_09_28_14_02_42_barcelona-dining-set_sm.jpg
                )

            [1] => Array
                (
                    [title] => Turned Leg Table
                    [img] => 2010_09_28_14_03_57_turned-leg-table_sm.jpg
                )

            [2] => Array
                (
                    [title] => Buffalo Chair
                    [img] => 2010_09_28_14_04_27_buffalo-chair-sm.jpg
                )

        )

)
With the code as it is now this is what I get
HullBorn is online now
Reply With Quote
View Public Profile
 
Old 12-23-2010, 08:04 PM Re: Array to create list with image problem
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I've taken a closer look at your code. Here is what I think you need to do:

PHP Code:
$img = array();
while(
$result mysql_fetch_array($result1)) {  
    
$combinedResults[$result['sect_name']][] = array(
      
'title' => $result['art_title'],
      
'img' => $result['art_image1'],
    );
    
$img[] = $result['sect_image']; //Set image here
    

Notice I made $img an array. This way you don't overwrite the previous section image when on this line:
PHP Code:
$img[] = $result['sect_image']; //Set image here 
All you should need to do is output it. array_shift just removes and then returns the first element in the array:
PHP Code:
$sectlist .= "<li>".$groupKey'<img src="' array_shift($img) . '" />' PHP_EOL//Need image here 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-24-2010, 05:58 AM Re: Array to create list with image problem
Skilled Talker

Posts: 50
Trades: 0
Cheers NullPointer,

I'll give it a go and let you know.

Thanks again

Wayne.
HullBorn is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to Array to create list with image problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38229 seconds with 12 queries