/    Sign up×
Community /Pin to ProfileBookmark

php array problem

hello all, i want to fill a table like this…

[code=php]
$recipes = array(
‘Alfalfa’ => array(‘image’ => ‘images/autocomplete/fruits/alfalfa.jpg’, ‘description’ => ‘One cup of raw, sprouted alfalfa see ..’),
‘Artichoke’ => array(‘image’ => ‘images/autocomplete/fruits/artichoke.jpg’, ‘description’ => ‘One medium artichoke cooked with …’),
);
[/code]

and do it like this, it works but load one row not two:

[code=php]
$recipes = array();
while($sbrow_jok=mysql_fetch_array($sbrs_jok)){
$descr = substr($sbrow_jok[‘sb_description’],0,90);
if(strlen($sbrow_jok[‘sb_description’])>90){
$descr .= ” …”;
}
unset($arr);
$arr = array(‘image’ => ”.loadimage( $sbrow_jok[‘sb_dish_image’], $sbrow_jok[‘sb_dish_isdefault’], ‘2’).”, ‘description’ => ”.$descr.”);
$recipes = array(”.$sbrow_jok[‘sb_title’].” => $arr);
}
[/code]

any help????

if i do like this doesnt works either…
$recipes[] = array(”.$sbrow_jok[‘sb_title’].” => $arr);

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 04.2010 — Firstly, on a side note, there is no need to concatenate empty strings to either end of your variables when using them as an array key. So anyway, I think you're looking for something like:
[code=php]
<?php
$recipes = array();
while ($sbrow_jok = mysql_fetch_array($sbrs_jok)) {
$descr = substr($sbrow_jok['sb_description'], 0, 90);
if (strlen($sbrow_jok['sb_description']) > 90) {
$descr.= " ...";
}
$recipes[$sbrow_jok['sb_title']] = array(
'image' => loadimage($sbrow_jok['sb_dish_image'], $sbrow_jok['sb_dish_isdefault'], '2') ,
'description' => $descr
);
}
[/code]
×

Success!

Help @dpsim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...