Jump to content

mysql_fetch_array help


thomasw_lrd

Recommended Posts

Here is my code

 

// Show the events for this day:
$getEvent_sql = "SELECT cal_title, cal_description,
        date_format(cal_start_time, '%l:%i %p') as fmt_date FROM
        calendar WHERE month(cal_start_time) = '".$m."'
        AND dayofmonth(cal_start_time) = '".$d."' AND
        year(cal_start_time)= '".$y."' ORDER BY cal_start_time";
$getEvent_res = myload($getEvent_sql);
 echo "<pre>"; print_r($getEvent_res); echo "</pre>";
if (count($getEvent_res) > 0){

$event_txt = "<ul>";
    while($ev = mysql_fetch_array($getEvent_res)){
	echo "Inside";
	echo $ev;
        $event_title = stripslashes($ev["cal_title"]);
        $event_shortdesc = stripslashes($ev["cal_description"]);
        $fmt_date = $ev["fmt_date"];
        $event_txt .= "<li><strong>".$fmt_date."</strong>:
                  ".$event_title."<br/>".$event_shortdesc."</li>";
	echo $event_title;
    }
    $event_txt .="</ul>";
    mysql_free_result($getEvent_res);
} else {
    $event_txt = "";
}

if ($event_txt != ""){
    echo "<p><strong>Today's Events:</strong></p>
    $event_txt
    <hr/>";
}

 

I can't get inside the while loop.  The array is populated, I've checked that.  The count of $getEvent_res = 3.  echo "Inside", and echo $ev give me nothing.  Any ideas what I'm doing wrong? 

 

$getEvent_res = myload($getEvent_sql);  The myload is a custom function that just works, I didn't write it, but I know it works.

 

Link to comment
Share on other sites

$getEvent_res is (likely) an array. You cannot use mysql_ functions on it because it is not a mysql result resource.

 

What exactly does  echo "<pre>"; print_r($getEvent_res); echo "</pre>"; show?

 

And you should have error_reporting set to E_ALL and display_errors set to ON so that php will report and display all the errors it detects. You would be getting an error at the mysql_fetch_array() statement alerting you to the fact that $getEvent_res isn't a mysql result resource.

Link to comment
Share on other sites

Yeah, I keep forgetting about the error reporting.  I really need to turn that on.  I found the problem.  My date is not being selected correctly. 

 

Out of $getEvent_res is

Array

(

    [0] => Array

        (

            [0] =>

            Test

            [cal_title] =>

            Test

            [1] => Tesing

            [cal_description] => Tesing

            [2] => 1:00 AM

            [fmt_date] => 1:00 AM

        )

 

    [1] => Array

        (

            [0] =>

            1

            [cal_title] =>

            1

            [1] => 1

            [cal_description] => 1

            [2] => 1:00 AM

            [fmt_date] => 1:00 AM

        )

 

    [2] => Array

        (

            [0] =>

            1

            [cal_title] =>

            1

            [1] => 1

            [cal_description] => 1

            [2] => 1:00 AM

            [fmt_date] => 1:00 AM

        )

 

    [3] => Array

        (

            [0] =>

            1

            [cal_title] =>

            1

            [1] => 1

            [cal_description] => 1

            [2] => 4:00 AM

            [fmt_date] => 4:00 AM

        )

 

$getEvent_sql = "SELECT cal_title, cal_description,
        date_format(cal_start_time, '%l:%i %p') as fmt_date FROM
        calendar WHERE month(cal_start_time) = '".$m."'
        AND dayofmonth(cal_start_time) = '".$d."' AND
        year(cal_start_time)= '".$y."' ORDER BY cal_start_time";

 

The preceding code is supposed to select the date, but it only selects the time.  I'm starting on it right now, but any suggestions are greatly appreciated.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.