|
Posted by Rik on 07/28/07 03:33
On Sat, 28 Jul 2007 05:08:25 +0200, Daniel <d_pineault@hotmail.com> wrot=
e:
> 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 =3D array();
> $sql =3D mysql_query("SELECT event_start_time, event_title ".
> "FROM events ".
> "WHERE event_date =3D '$yearno-$monthno-$dayno' ORDER B=
Y
> event_start_time");
> while ($row =3D mysql_fetch_assoc($sql)) array_push($evnts,$row);
> return $evnts;
> }
>
> Then I use it in php as follows:
> $events =3D getEvents($year,month_number($month),getDayofMonth($curdt)=
);
> foreach ($events as $key =3D> $value) {
> echo $key['iId'] . "<br/>";
Euhm, doesn't that always just return only "<br/>"?
<do not pay attention to my rambling is the following doesn't make sense=
=
to you?
$key is an integer, or should be as this is the current code. Only if it=
=
gets cast to a string by the foreach function (which it doesn't AFAIK), =
so =
I'm going off on a ramble here: Would it be a string (which is isn't) th=
e =
[] makes some kind of sense: the nth character in the string. It only =
takes a number, so any endresult between the [] is cast to it (usually 0=
=
if fed a string). That would mean the first character.
So that, boys and girls, is what happens if you accidentaly lose track o=
f =
wether your variable is a string or an array. Particularly nasty when =
checking for wether some important key which controls further flow is se=
t.
Example:
$var =3D 'You think this is an array.';
if(isset($var['important key'])) echo 'my important key is =
'.$var['important key'];
Output:
my important key is Y
</ok, now pay attention again>
> foreach ($value as $ikey =3D> $ivalue) {
> echo $ivalue ." \n";
> }
echo $value['event_start_time'], $value['event_title']
> }
>
> 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.
See above, it's in the $value array, var_dump($value) to check what a =
variable holds while debugging.
-- =
Rik Wasmus
[Back to original message]
|