0

I am trying to execute the following MySQL query:

SELECT event.event_id, venue.venue_name, venue.alt_venue_name, venue.venue_address1, venue.cross_street, dictionary_city.city_name, venue.zip, dictionary_filter.filter_name, venue.capacity, event.start_date, event.end_date, dictionary_barType.is_ob, dictionary_barType.barType_name, event.barType_time, event.is_food, event.food_type, event.food_time, dictionary_age.age_name, dictionary_age.age_description, event.ticketCo_id, event.ticket_locator, event.ticket_left, event_description.description, event_highlight.highlight, event.event_tag, event.image_flyer, event.image_flyer_310x425, event.image_2, event.image_2_310x208, event.image_3, event.image_3_310x208

FROM event

LEFT JOIN venue
    ON venue.venue_id=event.venue_id
LEFT JOIN dictionary_city
    ON venue.city_id=dictionary_city.city_id
LEFT JOIN dictionary_filter
    ON venue.venueType_id=dictionary_filter.filter_id
LEFT JOIN dictionary_barType
    ON event.barType_id=dictionary_barType.barType_id
LEFT JOIN dictionary_age
    ON event.event_age_id=dictionary_age.age_id
LEFT JOIN event_highlight
    ON event_highlight.event_id=event.event_id  
LEFT JOIN event_description
    ON event_description.event_id=event.event_id        

WHERE event.event_id="".$event_id."";

When I run the query in PhP Admin it works fine, but when I add the code to my site, I get the following error

"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/nye/public_html/theballdrop.com/templates/template.event.php on line 29 - See more at: http://theballdrop.com/new-years-eve-madame-tussauds/#sthash.880jgbaa.dpuf"

The query it refers to is "if ($row = mysql_fetch_array($result)){"

I am not sure where to go from here. This is supposed to display information from multiple tables on a single page. $event_id is the variable and a specific event ID would determine the info to display for that specific event page.

please help.

===========================

Here is the entire code for the page:

    <?php 

    // FUNCTION: CONVERT DATE
    include (PATH . DIR_INCLUDE . "convert-time.php");

    // CONNECT TO NYE DATABASE
    include (PATH . DIR_TEMPLATE . "mysql-connect.php");

    $sql = "SELECT event.event_id, venue.venue_name, venue.alt_venue_name, venue.venue_address1, venue.cross_street, dictionary_city.city_name, venue.zip, dictionary_filter.filter_name, venue.capacity, event.start_date, event.end_date, dictionary_barType.is_ob, dictionary_barType.barType_name, event.barType_time, event.is_food, event.food_type, event.food_time, dictionary_age.age_name, dictionary_age.age_description, event.ticketCo_id, event.ticket_locator, event.ticket_left, event_description.description, event_highlight.highlight, event.event_tag, event.image_flyer, event.image_flyer_310x425, event.image_2, event.image_2_310x208, event.image_3, event.image_3_310x208 FROM nye_newyears.event LEFT JOIN venue ON venue.venue_id=event.venue_id LEFT JOIN dictionary_city ON venue.city_id=dictionary_city.city_id LEFT JOIN dictionary_filter ON venue.venueType_id=dictionary_filter.filter_id LEFT JOIN dictionary_barType ON event.barType_id=dictionary_barType.barType_id LEFT JOIN dictionary_age ON event.event_age_id=dictionary_age.age_id LEFT JOIN event_highlight ON event_highlight.event_id=event.event_id LEFT JOIN event_description ON event_description.event_id=event.event_id WHERE event.event_id=".$event_id."";

    $result = mysql_query($sql, $con);

    // START MYSQL QUERY        
    if ($row = mysql_fetch_array($result)){

    // VENUE INFORMATION
    $venueName          =   $row['venue_name'];         // OFFICIAL VENUE NAME
    $venueName2         =   $row['alt_venue_name'];     // NAME YOU WANT TO DISPLAY AT TOP OF EVENT PAGE
    $venueAddress       =   $row['venue_address1'];     // ADDRESS OF VENUE
    $venueCrossStreet   =   $row['cross_street'];       // CROSS STREETS
    $venueCity          =   $row['city_name'];          // VENUE CITY
    $venueState         =   $row['state_abb'];          // VENUE STATE
    $venueZip           =   $row['zip'];                // VENUE ZIP
    $venueType          =   $row['filter_name'];        // TYPE OF VENUE
    $venueCapacity      =   $row['capacity'];           // CAPACITY OF VENUE

    // EVENT INFORMATION
    $start              =   $row['start_date'];
    $startDate          =   convertDate ($start);       // START DATE OF EVENT
    $startTime          =   convertTime ($start);       // START TIME OF EVENT
    $end                =   $row['end_date'];
    $endDate            =   convertDate ($end);         // END DATE OF EVENT
    $endTime            =   convertTime ($end);         // END TIME OF EVENT
    $ob                 =   $row['is_ob'];              // IS THERE OPEN BAR? "YES" OR "NO"
    $obType             =   $row['barType_name'];       // TYPE OF OPEN BAR
    $obTimes            =   $row['barType_time'];       // OPEN BAR TIMES (START AND END)
    $food               =   $row['is_food'];            // IS THERE FOOD? "YES" OR "NO"
    $foodType           =   $row['food_type'];          // TYPE OF FOOD SERVED
    $foodTimes          =   $row['food_time'];          // TIMES FOOD BEING SERVED (START AND END)
    $eventAge           =   $row['age_name'];           // AGE RESTRICTION (IF ANY)
    $eventAge_descrip   =   $row['age_description'];
    $ticketCompany      =   $row['ticketCo_id'];        
    $ticketID           =   $row['ticket_locator'];     // WIDGET ID
    $ticketsLeft        =   $row['ticket_left'];        // TOTAL TICKETS LEFT
    $eventDescription   =   $row['description'];        // EVENT DESCRIPTION
    $eventHighlight     =   $row['highlight'];          // EVENT HIGHLIGHT
    $eventTag           =   $row['event_tag'];          // EVENT LISTING DESCRIPTION

    // EVENT IMAGES
    $flyer              =   $row['image_flyer'];            // FULL SIZE EVENT FLYER IMAGE
    $flyer_310x425      =   $row['image_flyer_310x425'];    // FLYER IMAGE - 310x425
    $image2             =   $row['image_2'];                // FULL SIZE IMAGE 2
    $image2_310x208     =   $row['image_2_310x208'];        // IMAGE 2 - 310x208
    $image3             =   $row['image_3'];                // FULL SIZE IMAGE 3
    $image3_310x208     =   $row['image_3_310x208'];        // IMAGE 3 - 310x208

}

    // VENUE MAP
    $venueMap ="$venueAddress+$venueCity+$venueState+$venueZip" ;

    // CLOSE DATABASE
    mysql_close($con);

    // INCLUDE GLOBAL HEADER
    include (PATH . DIR_INCLUDE . "site-header.php"); 

?>

<body>
<?php include_once(PATH . "analyticstracking.php") ?>
<div id="wrapper">
  <?php include (PATH . DIR_INCLUDE . "header.php"); ?>
  <div class="row">
    <div class="middle">
      <div class="wrapper event-header">
        <div class="left twoThird slogan"> <br />
          <h1>
            <?=$venueName2?>
          </h1>
          <h5>
            <?=$eventTag?>
          </h5>
        </div>
        <div class="left oneThird last"> <a class="buy-now" href="#tickets" ><span>Buy Now</span></a> <a href="#" class="greybutton">Ask a Question</a> </div>

        <!-- End: button --> 

      </div>
    </div>

    <!--End .middle -->

    <div class="wrapper">
      <div class="twoThird left columns">
        <div class="roundCorner">
          <div class="widget data flier-section">
            <div class="flier left"> <a href="<?=DIR_IMAGES?><?=$flyer?>" class="flyerzoom"><img src="<?=DIR_IMAGES?><?=$flyer_310x425?>" alt="<?=$venueName2?> New Years Eve 2014" width="310" height="425" /></a> </div>

            <!-- End @ left-->

            <div class="photos right"> <a href="<?=DIR_IMAGES?><?=$image2?>" class="flyerzoom"><img src="<?=DIR_IMAGES?><?=$image2_310x208?>" alt="<?=$venueName?> Times Square New Years Eve 2014" /></a> <a href="<?=DIR_IMAGES?><?=$image3?>" class="flyerzoom fit"><img src="<?=DIR_IMAGES?><?=$image3_310x208?>" alt="<?=$venueName?> Times Square New Years Eve" /></a> </div>

            <!-- End @ right slider--> 

          </div>

          <!-- End @ widget-->

          <div class="center detail">
            <div class="widget lightgray-base">
              <h3 class="widget-heading">Why We Recommend</h3>
              <ul class="blist">
                <?=$eventHighlight?>
              </ul>
            </div>
            <div class="widget">
              <h3 class="headingbar">Overview</h3>
              <?=$eventDescription?>
              <p><strong>About your Tickets:&nbsp;</strong> (1) Show up early and help reduce the wait time, (2) Make sure to have your physical ticket on hand because you will need to show it to NYPD and security upon request, (3) You accept the risks and agree to adhere to the NYPD rules and regulations for the evening, (4) If you select shipping as your delivery method, tickets will not be sent out until December, (5) A LIVE VIEW of The Ball Drop is not guaranteed. Large crowds should be expected</p>
            </div>
          </div>
        </div>

        <!-- End of main-->

        <div class="roundCorner"> <a name="tickets" ></a>
          <h3 class="widget-heading">Purchase Tickets
            <div class="info">Have a Question? Call <a href="tel:2122010735">212.201.0735</a> or email <a href="mailto:info@balldrop.com">info@balldrop.com</a> </div>
          </h3>
          <div class="widget data">
            <p>
              <?php 

                if ($ticketCompany == 1){



                    // START: CRAVE TICKETS WIDGET -->

                    echo "<iframe scrolling='auto' frameborder='0' width='99.5%' height='600' src='http://cravetickets.com/widgets/iframe/qU4owWdNmYt/".$ticketID."' ></iframe>";

                    // END: CRAVE TICKETS WIDGET -->



                } else if ($ticketCompany == 2){



                        // START: LAUGHSTUB TICKET WIDGET -->

                        echo "<script type='text/javascript' src='http://www.laughstub.com/embed/cart/index.cfm?showTimingID=".$ticketID."&bgcolor=E53D23&fontcolor=ffffff&&brand=ticketmob&displayTitle=no&affiliate=1087&checkout=pmtix'></script>";

                        // END: LAUGHSTUB TICKET WIDGET -->             

                    }

            ?>
            </p>
            <p><strong> Price increase warning:</strong> New Year's Eve ticket prices often go up significantly (100% +) the closer you get to New Years Eve. Also note that many NYE Events will sell out well in advance of New Years Eve. </p>
          </div>
        </div>
      </div>

      <!-- End @ twoThird-->

      <div class="oneThird sidebar last">
        <div class="roundCorner lightgray-base">
          <h3 class="widget-heading">What to know</h3>
          <div class="box data">
            <h4>Share This Event</h4>
            <p> <span class='st_facebook_large' displayText='Facebook'></span> <span class='st_twitter_large' displayText='Tweet'></span> <span class='st_plusone_large' displayText='Google +1'></span> <span class='st_linkedin_large' displayText='LinkedIn'></span> <span class='st_pinterest_large' displayText='Pinterest'></span> <span class='st_email_large' displayText='Email'></span> </p>
            <ul class="know-list">
              <li>
                <h5>START TIME</h5>
                <h4>
                  <?=$startDate?>
                  at
                  <?=$startTime?>
                </h4>
              </li>
              <li>
                <h5>END TIME</h5>
                <h4>
                  <?=$endDate?>
                  at
                  <?=$endTime?>
                </h4>
              </li>
              <li>
                <h5>ADDRESS</h5>
                <h4>
                  <?=$venueAddress?>
                  <br>
                  <?=$venueCrossStreet?>
                </h4>
              </li>
              <li>
                <h5>VENUE TYPE</h5>
                <h4>
                  <?=$venueType?>
                </h4>
              </li>
              <li>
                <h5>AGE REQUIREMENT</h5>
                <h4>
                  <?=$eventAge?>
                  <br />
                  <?=$eventAge_descrip?>
                </h4>
              </li>
              <li>
                <h5>CAPACITY</h5>
                <h4>
                  <?=$venueCapacity?>
                </h4>
              </li>
              <li>
                <h5>OPEN BAR</h5>
                <h4>
                  <?=$ob?>
                  |
                  <?=$obType?>
                  <br />
                  from
                  <?=$obTimes?>
                </h4>
              </li>
              <li>
                <h5>FOOD SERVED</h5>
                <h4>
                  <?=$food?>
                  |
                  <?=$foodType?>
                  <br />
                  from
                  <?=$foodTimes?>
                </h4>
              </li>
            </ul>
          </div>
        </div>

        <!-- End of roundCorner -->

        <div class="roundCorner lightgray-base">
          <h3 class="widget-heading">Map</h3>
          <div class="box"> <img src="http://maps.googleapis.com/maps/api/staticmap?center=<?=$venueMap?>&zoom=16&size=295x245&markers=size:mid%7Ccolor:red%7C<?=$venueMap?>&sensor=false">
            <div class="address"> <br />
              <h3>
                <?=$venueName?>
              </h3>
              <h5>
                <?=$venueAddress?>
                <br />
                <?=$venueCrossStreet?>
                <br />
                <?=$venueCity?>
                ,
                <?=$venueState?>
                <?=$venueZip?>
              </h5>
            </div>
          </div>
        </div>

        <!-- End of roundCorner -->

        <div class="banner-300"> <img class="fullWidth" src="<?=DIR_IMAGES?>banner-300.jpg"> </div>

        <!-- End @ Banner--> 

      </div>

      <!-- End of onethird--> 

    </div>

    <!-- End @ wrapper-->

    <div id="footer-top"> 

      <!-- START: SIMILAR PARTIES -->

      <div class="listing-wrapper">
        <h2 class="subHeading">We Recommend <a href="#" class="right view-all">More NYE Parties <strong>&#8250;</strong></a> </h2>
        <ul class="columns">
          <?php include (PATH . DIR_INCLUDE . "similar-parties.php"); ?>
        </ul>
      </div>

      <!-- END: SIMILAR PARTIES --> 

    </div>

    <!-- End @ footer-top -->

    <?php include (PATH . DIR_INCLUDE . "footer.php"); ?>
  </div>

  <!-- End @ row--> 

</div>

<!-- End @ wrapper-->

</body>
</html>
user2763616
  • 21
  • 1
  • 8
  • Please show how the `$result` object is created – 000 Sep 10 '13 at 05:18
  • You are using double quotes (`""`). Does it help if you replace these by `\""` and `"\"`? – Willem Van Onsem Sep 10 '13 at 05:19
  • please add your php code also. – Pradeeshnarayan Sep 10 '13 at 05:24
  • Its possible that the mysql server has not been connected on your server. Check your username and password. – Starx Sep 10 '13 at 05:26
  • @JoeFrambach Obviously that is a boolean, just like the error says. It would however be helpful to know if you execute any other queries before you execute this query, and see the code between where you execute the query and where you check the result. Check `mysql_error()`. – Sumurai8 Sep 10 '13 at 05:26
  • I had added the code for the entire page to where the query is... – user2763616 Sep 10 '13 at 05:33
  • The user and pass is correct...I connect for other queries on the same. – user2763616 Sep 10 '13 at 05:33
  • For the "" (double quotes) it's bc I am calling the variables...it has worked in other queries for the same site. – user2763616 Sep 10 '13 at 05:34
  • $result is created "$result = mysql_query($sql, $con);" $sql is my query and $con is pulled from "mysql-connect.php" that I include before the query – user2763616 Sep 10 '13 at 05:37
  • 2
    How about some **very basic** debugging? Right after `$result = mysql_query($sql, $con);` add `if (!$result) { die('Invalid query: ' . mysql_error());}`. Run it again and post **the actual error message** in your question. – peterm Sep 10 '13 at 05:41
  • Still using `mysql`? [Better upgrade now!](http://stackoverflow.com/q/13944956/112968) – knittl Sep 10 '13 at 05:43
  • It returned an error "Invalid query: No database selected" but I called for the database "FROM nye_newyears.event" -- when i run this same query (using a specific event ID in phpMyAdmin) I get a result – user2763616 Sep 10 '13 at 05:43
  • I am a beginning programmer...learning as I go...if I knew how to upgrade, I would be happy too... – user2763616 Sep 10 '13 at 05:44
  • `venue` or `nye_newyears` are the tables, not the database. You have to execute something like `mysql_select_db('your_db');` – knittl Sep 10 '13 at 05:45
  • I call for the database in my connection file ("mysql-connect.php") that I include before the query: – user2763616 Sep 10 '13 at 05:48
  • nye_newyears is the database and within that, I am calling data from multiple tables (in the LEFT JOIN) but I used "FROM nye_newyears.event" for my main table. – user2763616 Sep 10 '13 at 05:50
  • You never select the DB in the mysql extension, you only assign its name to a variable. – knittl Sep 10 '13 at 05:50
  • knittl, how do you select the DB in mysql extension? what would the code be then? – user2763616 Sep 10 '13 at 05:55
  • @user2763616: I already wrote that above, you have to call something akin to `mysql_select_db(…)` – knittl Sep 10 '13 at 05:58
  • Thank you all for your help. Knittl you were RIGHT!!! I added the following code to mysql-connect file: if(!mysql_select_db($dbname)) { die('Could not find database ' . $dbname); } everything works now. Thank you so much. – user2763616 Sep 10 '13 at 05:59
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – John Conde Sep 10 '13 at 11:50

4 Answers4

1

Add database selection to your connect script, like so:

<?php
$hostname = "localhost";
$username = "{username]";
$password = "[pass]";
$dbname = "nye_newyears";

$con = mysql_connect("$hostname", "$username", "$password");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

if(!mysql_select_db($dbname)) {
    die('Could not find or access database ' . $dbname);
}
?>
Arjan
  • 9,784
  • 1
  • 31
  • 41
0

event is a keyword in mysql. so wrap it inside quotes (`) and try.

echo your $sql in browser copy it and paste it in phpmyadmin and execute, you will get the particular error if any.

Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73
0

At first, check your MySql Table name in server. Sometimes some hosts add a prefix on table name.

You should check $result object first like

if(!$result){
  exit(mysql_error());
}else{
  if ($row = mysql_fetch_array($result)){
   // ....
   // ...
  }
}
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
Sarwar Hasan
  • 1,561
  • 2
  • 17
  • 25
0

Thank you all for your help. Knittl you were RIGHT!!!

I added the following code to mysql-connect file:

if(!mysql_select_db($dbname)) {
    die('Could not find database ' . $dbname);
}

everything works now.

Thank you so much.

user2763616
  • 21
  • 1
  • 8
  • [Aryan already gave the same answer](http://stackoverflow.com/a/18711542/112968). You should accept his. – knittl Sep 11 '13 at 07:56