Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Nov 2005
    Posts
    10
    Member #
    11976
    Hi, I am new to this forum. I am trying to create a calendar with event links, and get these event links from my database. If there is no event on the date, the number is simply displayed. However, if there is an event/s then the event name and store name is displayed. This is a website with events from stores displayed on a calendar. The tables involved are a calendar table, event table, and store table. The calendar displays and the days with no events display, but the echo line in the while($row = mysql_fetch_array($result)) statement, does not display, leaving an empty square in the table. It obviously recognizes that an event occurs on this date, but it does not echo the eventname or storename. Any suggestions?


    CODE SNIPPET:

    // Select eventId and storeId from the date given
    $chkEvent = "SELECT `eventId` , `storeId` FROM `calendar` WHERE `day` = '".$dayArray['mday']."' AND `month` = '$month' AND `year` = '$year' LIMIT 0, 30";
    $chkEvent_res = @mysql_query($chkEvent) or die(mysql_error());

    // If there is an event, display
    if (@mysql_num_rows($chkEvent_res) > 0)
    {
    while ($ev = @mysql_fetch_array($chkEvent_res))
    {
    $eventId = $ev['eventId'];
    $storeId = $ev['storeId'];

    // Select name of event from eventId in event table and name of store from storeId in store table
    $getEvent = "SELECT event.name, store.name FROM event, store WHERE 'eventId' = '$eventId' AND 'storeId' = '$storeId'";

    $result = mysql_query($getEvent,$conn) or die(mysql_error());

    // While there are rows to read, extract event name and store name
    while($row = mysql_fetch_array($result))
    {
    $eventName = $row['event.name'];
    $storeName = $row['store.name'];

    echo "<td><a>".$dayArray['mday']."</a> <br> $eventName, $storeName <br></td>\n";
    }
    }
    }
    else
    {
    echo "<td>".$dayArray['mday']."</td>\n";
    }

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    So it outputs a blank event name and store name? If that's what's happening, do a:
    PHP Code:
    while($row mysql_fetch_array($result))
    {
        
    print_r($row);

    To make sure that you are using the right array indices (i.e., is it really $row['event.name'], $row['store.name']). I believe this is your problem, as phpMyAdmin is showing both of these would probably be returned as `name'.

    Try changing your query to:
    PHP Code:
    $getEvent "SELECT event.name AS 'event.name', store.name AS 'store.name' FROM event, store WHERE 'eventId' = '$eventId' AND 'storeId' = '$storeId'"
    Then your present code should work.

  4. #3
    Junior Member
    Join Date
    Nov 2005
    Posts
    10
    Member #
    11976
    Quote Originally Posted by Shadowfiend
    So it outputs a blank event name and store name? If that's what's happening, do a:
    PHP Code:
    while($row mysql_fetch_array($result))
    {
        
    print_r($row);

    To make sure that you are using the right array indices (i.e., is it really $row['event.name'], $row['store.name']). I believe this is your problem, as phpMyAdmin is showing both of these would probably be returned as `name'.

    Try changing your query to:
    PHP Code:
    $getEvent "SELECT event.name AS 'event.name', store.name AS 'store.name' FROM event, store WHERE 'eventId' = '$eventId' AND 'storeId' = '$storeId'"
    Then your present code should work.


    The print function didn't display anything. I know that it recognizes that a certain day has an event because the on the day of the one event i have as a test in the db, no <td> even shows up. SO it isn't printing that echo statement at all.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Get rid of the @s and make sure that there are no errors spit out (you'll have to check the source, since if you're spitting out an error in the middle of a table outside a td it tends to be invisible). It's very likely there's something wrong with your function call or something (I'd be using mysql_fetch_assoc, to be perfectly honest, but that's personal preference, not a coding error).

  6. #5
    Junior Member
    Join Date
    Nov 2005
    Posts
    10
    Member #
    11976
    Quote Originally Posted by Shadowfiend
    Get rid of the @s and make sure that there are no errors spit out (you'll have to check the source, since if you're spitting out an error in the middle of a table outside a td it tends to be invisible). It's very likely there's something wrong with your function call or something (I'd be using mysql_fetch_assoc, to be perfectly honest, but that's personal preference, not a coding error).
    There is no error in the source as far as i can see.
    It shows:

    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    </tr><tr>
    <td>6</td>
    <td>7</td>
    <td>8</td>...

    It is not even printing the <td></td> for the 5th (The date that has an event in the db).

    What is the difference between mysql_fetch_assoc and mysql_fetch_array? I'm really new to this stuff so I just use what I read in books I have.

  7. #6
    Junior Member
    Join Date
    Nov 2005
    Posts
    10
    Member #
    11976
    I tried it a different way, and the <td> is echoed this time, but the eventName and storeName are still not printing. But I think this way makes more sense, at least to me.

    CODE SNIPPET:
    // Select eventId and storeId from the date given
    $chkEvent = "SELECT `eventId` , `storeId` FROM `calendar` WHERE `day` = '".$dayArray['mday']."' AND `month` = '$month' AND `year` = '$year' LIMIT 0, 30";
    $chkEvent_res = mysql_query($chkEvent) or die(mysql_error());

    // If there is an event, display
    if (mysql_num_rows($chkEvent_res) > 0)
    {
    while ($ev = mysql_fetch_array($chkEvent_res))
    {
    $eventId = $ev['eventId'];
    $storeId = $ev['storeId'];

    // Select name of event from eventId in event table and name of store from storeId in store table
    $getStore = "SELECT name FROM store WHERE 'storeId' = '$storeId'";
    $resultStore = mysql_query($getStore,$conn) or die(mysql_error());
    $rowS = mysql_fetch_array($resultStore);
    $storeName = $rowS['name'];

    $getEvent = "SELECT name FROM event WHERE 'eventId' = '$eventId'";
    $resultEvent = mysql_query($getEvent,$conn) or die(mysql_error());
    $rowE = mysql_fetch_array($resultEvent);
    $eventName = $rowE['name'];

    echo "<td><a>".$dayArray['mday']."</a> <br> $eventName, $storeName <br></td>\n";
    }
    }
    else
    {
    echo "<td>".$dayArray['mday']."</td>\n";
    }

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Your two getStore and getEvent queries do a WHERE 'column'; that should either be a WHERE `column` or a WHERE column (no backticks or quotes). Aside from that, it looks like everything should work.

    Also, when posting PHP, go ahead and wrap it in . That makes it fixed-width, includes the tabs, and gives us syntax highlighting which makes the code much easier to understand :-)

  9. #8
    Junior Member
    Join Date
    Nov 2005
    Posts
    10
    Member #
    11976
    Quote Originally Posted by Shadowfiend
    Your two getStore and getEvent queries do a WHERE 'column'; that should either be a WHERE `column` or a WHERE column (no backticks or quotes). Aside from that, it looks like everything should work.

    Also, when posting PHP, go ahead and wrap it in . That makes it fixed-width, includes the tabs, and gives us syntax highlighting which makes the code much easier to understand :-)
    That works! Thanks so much for all your help! Next time I'll be sure to wrap it - Sorry!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com