/    Sign up×
Community /Pin to ProfileBookmark

Array Index Help

So I realize that the code below doesn’t work, how can I do this though?

[code=php]$array[title][0][/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 18.2008 — What do you want to do?
Copy linkTweet thisAlerts:
@GreyfishauthorSep 18.2008 — Well I'm grabbing rows of information from a database but I only want to print out the "title" row but not every title just the one with the given index.
Copy linkTweet thisAlerts:
@NogDogSep 18.2008 — Well I'm grabbing rows of information from a database but I only want to print out the "title" row but not every title just the one with the given index.[/QUOTE]
Um...OK...so...where does [b]$array[/b] come from? At this point I still really have no idea what your code does. If $array is a 2-dimension array of each query result row, probably all you need is to reverse the indexes: $array[0]['title'], but I'm really not sure at this point.
Copy linkTweet thisAlerts:
@GreyfishauthorSep 18.2008 — Ahh sorry, my array comes from information stored in a database...here is my code.

[code=php]$getSpotlights = mysql_query("SELECT * FROM spotlight WHERE type='spotlight'");
$getHighlights = mysql_query("SELECT * FROM spotlight WHERE type='highlight'");
$getTotal = mysql_num_rows($getSpotlights);
$printed = 0;
$break = ceil($getTotal/2);

echo "<?xml version="1.0"?>n";
echo "<rss version="2.0" encoding="UTF-8">n";
echo "<channel>n";
echo "n";
echo "t<title>Example</title>n";
echo "t<link>http://www.example.com</link>n";
echo "t<description>Ministry spotlights and information on upcoming events.</description>n";
echo "t<language>en-us</language>n";
echo "t<generator>PHP Baby!</generator>n";
echo "n";
while($spotlight = mysql_fetch_array($getSpotlights)){
echo "t<item>n";
echo "tt<title>$spotlight[title]</title>n";
echo "tt<link>$spotlight[link]</link>n";
echo "tt<description>$spotlight[description]</description>n";
echo "tt<media>$spotlight[media]</media>n";
echo "t</item>n";
echo "n";
$printed++;
if($printed == $break){
$highlight = mysql_fetch_array($getHighlights);
echo "t<item>n";
echo "tt<title>$highlight[title][0]</title>n";
echo "tt<link>$highlight[link][0]</link>n";
echo "tt<description>$highlight[description[0]</description>n";
echo "tt<media>$highlight[media][0]</media>n";
echo "t</item>n";
echo "n";
}
}
echo "</channel>n";
echo "</rss>n";[/code]
Copy linkTweet thisAlerts:
@NogDogSep 18.2008 — For the current code, I see no need for the [0] index. If, however, the intent is to get the values from a particular result row, then before you make the call to mysql_fetch_array($getHighlights), do a mysql_data_seek($row) where $row is the desired result row number (starting at 0 for the first row).
×

Success!

Help @Greyfish 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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