|
Posted by Matt Madrid on 07/28/07 03:20
Daniel wrote:
> Hello,
>
> I am very new to php/MySQL and know this question has been answered
> before (I can't seem to locate it however).
>
> I created a function that pull data from a MySQL db. I use the
> returned values using php to generate my html page. The question
> being that the qeury returns 2 values. right now I simply loop
> through all the values and output them sequentially. However, I need
> more control over these values. How can I call each value
> independantly (instead of looping)?
>
> function getEvents($yearno,$monthno,$dayno) {
> $evnts = array();
> $sql = mysql_query("SELECT event_start_time, event_title ".
> "FROM events ".
> "WHERE event_date = '$yearno-$monthno-$dayno' ORDER BY
> event_start_time");
> while ($row = mysql_fetch_assoc($sql)) array_push($evnts,$row);
> return $evnts;
> }
>
> Then I use it in php as follows:
> $events = getEvents($year,month_number($month),getDayofMonth($curdt));
> foreach ($events as $key => $value) {
> echo $key['iId'] . "<br/>";
> foreach ($value as $ikey => $ivalue) {
> echo $ivalue ." \n";
> }
> }
>
> Instead of looping through each $ivalue, I am looking for a way to
> call the 'event_start_time' and 'event_title' as I need the to
> appear. i am trying to build an a href statement with this
> information.
>
> Thank you,
>
> Daniel
>
In your first foreach loop, $value is an associative array, with the
keys being the column names. So you can dispose of the second foreach
loop and:
echo $value['event_start_time'];
Matt M.
Navigation:
[Reply to this message]
|