www.webdeveloper.com
Results 1 to 8 of 8

Thread: carrying variable through while if statments....

  1. #1
    Join Date
    May 2006
    Posts
    47

    carrying variable through while if statments....

    Hi,

    I am outputting my database content througha while statement, and have used an if else inside this to display separate content depending on whether a tick box has been used on the CMS admin side by my client -

    the problem is:

    i cant carry across my $title variable (which grabs the title from the 'title' field of my db - and passes this to the proceeding contact form - if you click the enquiry button to the right - it passes the last db rows title field across instead -

    any ideas? - this works fine for my othe rpages, but the this page uses a while to display data - and this is whats causing the problem -

    any suggestions - ??

    help appreciated as always!!

    Aaron

    see code below - page in question is http://www.partyco.org/hen-stag-part...?location=Bath

    <?php
    $location = $_GET['location'];
    ?>

    <div id="mainContent">

    <?php include("../include/shareLinks.php"); ?>

    <h1>Stag Weekend Packages in <?php echo $location ?></h1>

    <p><b>For a stag night, stag weekend or just a fun boys' day or night out,</b> we offer you the chance to build your own stag party itinerary, including accommodation, daytime and nightime activities. In each destination you will also find a few of our most popular ‘pre built stag party packages’ which you can book online or simply use as inspiration for creating your own stag party package.<br/><br/></p>



    <?php

    $Link = mysql_connect("cust-mysql-123-01", "upartyc_495097_1", "partYweb1979") or die(mysql_error());
    mysql_select_db("partycoorg_495097_db1") or die(mysql_error());

    $query = "SELECT * FROM stag WHERE location = '$location'";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){

    $yes = $row['outsource'];

    $title = $row['title'];

    if (empty($yes)) {


    echo "<div class=\"resultsShorthenstag\">";
    echo "<h2 id=\"resultsHeading2\">";
    echo $row['title'];
    echo "</h2>";
    echo "<p class=\"subHeadingPara\">";
    echo "<span class=\"priceSubHeading\">Price:</span>". "<b>&pound;". $row['price']. "</b>";
    echo "</p>";
    echo "<div style=\"float:left; width:411px; margin-right:12px;\">";
    echo "<p class=\"resultspara\">";
    echo $row['description'];
    echo "</p></div>";
    echo "<div class=\"button\" style=\"float:left; width:124px; height:40px; margin:10px 0 0 0;\">";
    echo "<submit type=\"submit\" class=\"button\" value=\"MAKE ENQUIRY\" />";
    echo "</div>";


    } else {

    echo "<div class=\"resultsShorthenstag\">";
    echo "<h2 id=\"resultsHeading2\">";
    echo $row['title'];
    echo "</h2>";
    echo "<p class=\"subHeadingPara\">";
    echo "<span class=\"priceSubHeading\">Price:</span>". "<b>&pound;". $row['price']. "</b>";
    echo "</p>";
    echo "<p class\"resultspara\">";
    echo "<a href=\"http://". $row['link']. "\" target=\"_blank\" title=\"Make an enquiry\">";
    echo "<img id=\"henstagbtn\" src=\"/images/party-planning-enquiry.jpg\" align=\"right\" width=\"124\" height=\"35\" alt=\"enquiry button\" border=\"0\" /></a>";
    echo $row['description'];
    echo "</p>";
    echo "</div>";
    }

    }

    ?>



    <div id="popupContact">
    <a id="popupContactClose" title="close this window">close x</a>
    <h1>Stag Night Enquiry Form</h1>
    <?php include("../include/enquiryform.php"); ?>
    </div>
    <div id="backgroundPopup"></div>


    <?php
    mysql_close ($Link);
    ?>

  2. #2
    Join Date
    Aug 2007
    Location
    Leeds, Yorkshire, England
    Posts
    387

  3. #3
    Join Date
    May 2006
    Posts
    47
    Dont need to use sessions, I only interested in one click on that same page, not whether they click somewhere else later with the same session id - the problem is that the last row that gets displayed on that page - is where the $title gets taken from - but I want the title to be taken from the first or 2nd rows - because of the while loop, it is taking the title from the last row printed - how do I get around that?

    try and see - click the enquire button on the first row and it uses the last ros title info , not the first rows title

    thanks anyway

  4. #4
    Join Date
    Jun 2005
    Location
    Fullerton, CA USA
    Posts
    61
    Replace the current assignment with:

    Code:
    if ( empty( $title )) $title = $row['title'];

  5. #5
    Join Date
    May 2006
    Posts
    47

    thanks,

    but now it only uses the title field fom the first row - ultimate stag weekend - try clicking the laugh a minute enquire button.....??


    <?php

    $Link = mysql_connect("cust-mysql-123-01", "upartyc_495097_1", "partYweb1979") or die(mysql_error());
    mysql_select_db("partycoorg_495097_db1") or die(mysql_error());

    $query = "SELECT * FROM stag WHERE location = '$location'";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){

    $yes = $row['outsource'];

    if ( empty( $title )) $title = $row['title'];

    if (empty($yes)) {

    echo "<div class=\"resultsShorthenstag\">";
    echo "<h2 id=\"resultsHeading2\">";
    echo $row['title'];
    echo "</h2>";
    echo "<p class=\"subHeadingPara\">";
    echo "<span class=\"priceSubHeading\">Price:</span>". "<b>&pound;". $row['price']. "</b>";
    echo "</p>";
    echo "<div style=\"float:left; width:411px; margin-right:12px;\">";
    echo "<p class=\"resultspara\">";
    echo $row['description'];
    echo "</p></div>";
    echo "<div class=\"button\" style=\"float:left; width:124px; height:40px; margin:10px 0 0 0;\">";
    echo "<submit type=\"submit\" class=\"button\" value=\"MAKE ENQUIRY\" />";
    echo "</div>";
    echo "</div>";


    } else {

    echo "<div class=\"resultsShorthenstag\">";
    echo "<h2 id=\"resultsHeading2\">";
    echo $row['title'];
    echo "</h2>";
    echo "<p class=\"subHeadingPara\">";
    echo "<span class=\"priceSubHeading\">Price:</span>". "<b>&pound;". $row['price']. "</b>";
    echo "</p>";
    echo "<p class\"resultspara\">";
    echo "<a href=\"http://". $row['link']. "\" target=\"_blank\" title=\"Make an enquiry\">";
    echo "<img id=\"henstagbtn\" src=\"/images/party-planning-enquiry.jpg\" align=\"right\" width=\"124\" height=\"35\" alt=\"enquiry button\" border=\"0\" /></a>";
    echo $row['description'];
    echo "</p>";
    echo "</div>";
    }

    }

    ?>

  6. #6
    Join Date
    Jun 2005
    Location
    Fullerton, CA USA
    Posts
    61
    Well, I'm confused. You said "I want the title to be taken from the first or 2nd rows". And while you didn't say how you'd decide if it were the first or second row, you did seem to indicate that you didn't care about matching up the db row's "title" value with the individual button generated for that row.

    What am I missing? Where is the "title" supposed to come from for each button?

  7. #7
    Join Date
    May 2006
    Posts
    47
    Hi,

    sorry, my confusion. I want the title to be pulled from the row heading 'title' so that it is used in the bottom corner of the enquiry form when clicked on the form button next to the listing....it is not sending the correct title - something to do with an if..else inside the while...............

    thanks,

    Aaron

  8. #8
    Join Date
    Jun 2005
    Location
    Fullerton, CA USA
    Posts
    61
    Since I had a little time on my hands due to a server being down, I dived into your code and came to a realization: while you are using a submit button in your page, you're not actually creating a form. And you're doing nothing to differentiate one button from another (unless you're setting a JPG image because it's an "outsourced" item).

    Which means you must be reading the variable $title out of context: you're not passing data to a responding routine, you're just reading whatever value got left in that variable. It has nothing whatsoever to do with the if-else logic.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles