SitePoint Sponsor

User Tag List

Page 2 of 4 FirstFirst 1234 LastLast
Results 26 to 50 of 81
  1. #26
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks cpradio, that worked perfectly.

    I'm thinking of the next step now, and will give that a go.

    The next step is to build the query up to display the hotels going by the values in the array I suppose, as those numbers are the Id's of the regions.

    I will do some investigating and make a start and will likely return, but thank you for the help so far.

  2. #27
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I havent started on the other bit yet, as I needed to draw the names out of the database of the regions rather than the id's to show, so I used the code below, which works, but it only seems to draw out a couple of the names of the regions not all of them.

    http://devchecksafetyfirst.csf.dcmanaged.com/

    PHP Code:
    <?php   
    $r
    =mysql_query("select * from tbl_contnreg where (Id_Cntry='1')");  
    while(
    $q=mysql_fetch_assoc($r)){ ?> 
    <input type="checkbox" name="regions[]" value="<?=$q['Id_Rsrt']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Rsrt'], $_REQUEST['regions'])) ? "checked=\"checked\"" "")?> />
        <?php
        $m
    =mysql_query("select Id_Rsrt, Nom_Rsrt from tbl_resorts where (Id_Rsrt=".$q['Id_Rsrt'].")");  
        if(
    $b=mysql_fetch_assoc($m)){ ?> 
        <?=$b['Nom_Rsrt']?> 
        <? ?><br/> 
    <? ?>
    cant think of the problem

  3. #28
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh hang on, it doesnt look like its a code issue, more of what is being displayed.

    need to look into this, sorry should have checked first.

    Ye sorry about that, it was my fault, all looking good now.

    First bit done!

  4. #29
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by multichild View Post
    Oh hang on, it doesnt look like its a code issue, more of what is being displayed.

    need to look into this, sorry should have checked first.

    Ye sorry about that, it was my fault, all looking good now.

    First bit done!
    Probably a query issue, but if you need help, describe the problem in a bit more detail and I'll be glad to assist.

  5. #30
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whilst looking at another area I'm also looking at how to get the array set properly to use it when selecting from the database, and I have below sort of working, but its bringing back the results and also it seems to be doubling up, and doing some strange things.

    There something not quite right with it.

    PHP Code:
    if (is_array($_GET['regions'])) {
         foreach(
    $_GET['regions'] as $regions) {
             
    $regionsArray[] = '\''.$regions.'\'';
           
    //echo $regions;
         
    $ids implode(','$regionsArray);
           echo 
    $ids;
         }

    You can see the array in the dev area building below, and the added values in the array

    http://devchecksafetyfirst.csf.dcman...ions%5B%5D=255

  6. #31
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Its your code You have the echo statement inside the foreach loop, dope! So you are echoing it out on every iteration.

    PHP Code:
    if (is_array($_GET['regions'])) { 
         
    $regionsArray = array();
         foreach(
    $_GET['regions'] as $regions) { 
             
    $regionsArray[] = '\''.$regions.'\''
         } 
           
    //echo $regions; 
         
    $ids implode(','$regionsArray); 
         echo 
    $ids


  7. #32
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL, i've just set myself back 5 years...

    Sorry cpradio, yep thats it, works fine now.

    (
    [regions] => Array
    (
    [0] => 160
    [1] => 155
    [2] => 288
    [3] => 157
    [4] => 255
    [5] => 305
    [6] => 156
    [7] => 340
    )

    )

    '160','155','288','157','255','305','156','340'

    Cheers

  8. #33
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm moving through this a bit every day now, and im now trying to tie things up in the select from database operation, but the code below is now not working, when the simpler version was.

    PHP Code:
    $sql.= "SELECT * FROM tbl_hotels " . $sqlregion . " ";
    $sql.= " order by Id_Hot";
    while($q=mysql_fetch_assoc($sql)){ ?>
    <p><?=$q['Nom_Hot']?></p>
    The simpler version

    PHP Code:
    $sql = mysql_query("SELECT * FROM tbl_hotels " . $sqlregion . " order by Id_Hot");
    while($q=mysql_fetch_assoc($sql)){ ?>
    <p><?=$q['Nom_Hot']?></p>

  9. #34
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    What is the value of $sqlregion?

  10. #35
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its the array for the regions bit

    PHP Code:
    if (is_array($_GET['regions'])) {
         
    $regionsArray = array();
         foreach(
    $_GET['regions'] as $regions) {
         
    $regionsArray[] = '\''.$regions.'\'';
         
    $regionData implode(','$regionsArray);
         
    $sqlregion =  'WHERE IdRsrt_Hot IN ('$regionData .' )';
         }
         
    //echo $regionData;
         //echo $sqlregion;

    So at this very moment its - WHERE IdRsrt_Hot IN ('155','157','255','340' )

    http://devchecksafetyfirst.csf.dcman...ions%5B%5D=340

  11. #36
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose this below would be more like where Im trying to get too, or build up.

    Im going to use if statements to see whether to use the different arrays or not.

    PHP Code:
    $sql.= " select * from tbl_hotels ";
    $sql.= " " .$sqlregion . "";
    $sql.= " order by Id_Hot";
    while($q=mysql_fetch_assoc($sql)){ ?>
    <p><?=$q['Nom_Hot']?></p>

  12. #37
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Okay, two things.
    1) Be aware of what is in your foreach! (see comments below)
    PHP Code:
    if (is_array($_GET['regions'])) { 
         
    $regionsArray = array(); 
         foreach(
    $_GET['regions'] as $regions) { 
         
    $regionsArray[] = '\''.$regions.'\''
         
    $regionData implode(','$regionsArray); // should be outside your foreach
         
    $sqlregion =  'WHERE IdRsrt_Hot IN ('$regionData .' )';  // should be outside your foreach
         

         
    //echo $regionData; 
         //echo $sqlregion; 

    2) Call mysql_query; mysql_fetch_assoc only works with a mysql_query result, you never called mysql_query passing in your $sql...
    PHP Code:
    $sql.= " select * from tbl_hotels "; 
    $sql.= " " .$sqlregion . ""; 
    $sql.= " order by Id_Hot"; 
    while($q=mysql_fetch_assoc($sql)){ ?> 
    <p><?=$q['Nom_Hot']?></p>

  13. #38
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thank you on the first bit, didnt realise to do that, but yes it does make sense now.
    PHP Code:
    if (is_array($_GET['regions'])) {
         
    $regionsArray = array();
         foreach(
    $_GET['regions'] as $regions) {
         
    $regionsArray[] = '\''.$regions.'\'';
         }
         
    $regionData implode(','$regionsArray);
         
    $sqlregion =  'WHERE IdRsrt_Hot IN ('$regionData .' )';
         
    //echo $regionData;
         //echo $sqlregion;

    The second bit i added it in and now i get white out:

    PHP Code:
    $sql.=mysql_query("select * from tbl_hotels ";
    $sql.= "" .$sqlregion . "";
    $sql.= " order by Id_Hot");
    while($q=mysql_fetch_assoc($sql)){ ?>
    <p><?=$q['Nom_Hot']?></p>

  14. #39
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that isn't a legal syntax there...

    This would be prefered:
    PHP Code:
    $sql.="select * from tbl_hotels "; 
    $sql.= "" .$sqlregion . ""; 
    $sql.= " order by Id_Hot"; 
    while($q=mysql_fetch_assoc(mysql_query($sql))){  // place mysql_query here
    ?> 
    <p><?=$q['Nom_Hot']?></p>

  15. #40
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code cpradio is causing it to output the same thing over and over, the page is taking a long time to load.

    It takes ages to display, then when it did all i could see was the first result over and over again.

    PHP Code:
    $sql.="select * from tbl_hotels "; 
    $sql.= "" .$sqlregion . ""; 
    $sql.= " order by Id_Hot"; 
    while($q=mysql_fetch_assoc(mysql_query($sql))){ 
    ?> 
    <p><?=$q['Nom_Hot']?></p>
    <? ?>

  16. #41
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Hmm, okay, so it must be executing the mysql_query($sql) on each loop.

    Try this:
    PHP Code:
    $sql.="select * from tbl_hotels ";  
    $sql.= "" .$sqlregion . "";  
    $sql.= " order by Id_Hot";  
    $result = mysql_query($sql);
    while($q=mysql_fetch_assoc($result)){  
    ?>  
    <p><?=$q['Nom_Hot']?></p> 
    <? ?>

  17. #42
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ye thats it, thanks cpradio.

    keep on trucking!

  18. #43
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to give some feedback of choice back to the user in the form of a sort of breadcrumb and get the name I need from the checkboxes, but the name that shows on the site is what I want not the id that I am passing into the array, so I thought about using a hidden type field, and it sort of done the job but instead pf picking out the ones that have been selected, instead it echo'd out all the names of the regions.

    http://devchecksafetyfirst.csf.dcman...e%5B%5D=Zarzis

    Si I tried this below:

    Code:
    <input type="checkbox" name="regions[]" value="<?=$q['Id_Rsrt']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Rsrt'], $_REQUEST['regions'])) ? "checked=\"checked\"" : "")?> class="inline" /> <?=$q['Nom_Rsrt']?><br/> 
    <input type="hidden" name="regionsName[]" value="<?=$q['Nom_Rsrt']?>" <?=((in_array($q['Nom_Rsrt'], $_REQUEST['regionsName'])) ? "checked=\"checked\"" : "")?> class="inline" />
    But like i said i got all of the names out, what do you think is the best way to get the selected names out ="<?=$q['Nom_Rsrt']?> as well as the id's ="<?=$q['Id_Rsrt']?>

  19. #44
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    I'm not following... You know what regions were requested they are in $_REQUEST['regions'], just create a list of them and get the names from the table for your breadcrumb...

  20. #45
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh right ye, ye maybe i was trying to hard there.

    What I did was created another array.

    PHP Code:
    if (is_array($_GET['regionsName'])) {
         
    $regionsNameArray = array();
         foreach(
    $_GET['regionsName'] as $regionsName) {
         
    $regionsNameArray[] = '\''.$regionsName.'\'';
         }
         
    $regionNameData implode(','$regionsNameArray);
         
    //$sqlregion =  'WHERE IdRsrt_Hot IN ('. $regionNameData .' )';     
         
    echo $regionNameData;
         
    //echo $sqlregion;

    And then tried to capture the name of the region rather than its ID through a hidden input.

    But ye I could use the array to search and display those names that way isnt it.

  21. #46
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ye got it now, sorry to bother you on that one cpradio.

    I tried to be too clever then, and it was in a way the most diificult way.

    PHP Code:
    $sqlregionName =  'WHERE Id_Rsrt IN ('$regionData .' )'
    Code:
    <div style="position:relative; width:100%; height:30px; text-align:left; padding-left:20px; line-height:28px;">
    Breadcrumb: <? $q=mysql_query("select Id_Rsrt, Nom_Rsrt from tbl_resorts " . $sqlregionName . "");  
    while($n=mysql_fetch_assoc($q)){ ?> 
    <?=$n['Nom_Rsrt']?>,
    <? } ?>
    </div>
    Just the job

  22. #47
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At first glance, do you see anything wrong with the code of below:

    PHP Code:
    <?php
    $r
    =mysql_query("select Id_Rsrt, Nom_Rsrt, IdCntry_Rsrt, Id_show from tbl_resorts where (IdCntry_Rsrt='7') and (Id_show='1') order by Nom_Rsrt ASC");  
    while(
    $q=mysql_fetch_assoc($r)){ ?> 
    <input type="checkbox" name="regions[]" value="<?=$q['Id_Rsrt']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Rsrt'], $_REQUEST['regions'])) ? "checked=\"checked\" " "")?> class="inline" /> <?=$q['Nom_Rsrt']?><br/>

    <?
    $queryNumber 
    mysql_query("select count(Id_Hot) as total from tbl_hotels where ('IdRsrt_Hot="$q['Id_Rsrt'] . "') and (Act_Hot='1') ");
    $resultNumber mysql_fetch_array($queryNumber);
    echo 
    $resultNumber['total'];
    ?>

    <? ?>
    I'm not getting any errors, just not getting the result I need.

    I basically want to display how many hotels are in each regions depending on the values, its this part im trying to get right

    PHP Code:
    <?php
    $queryNumber 
    mysql_query("select count(Id_Hot) as total from tbl_hotels where ('IdRsrt_Hot="$q['Id_Rsrt'] . "') and (Act_Hot='1') ");
    $resultNumber mysql_fetch_array($queryNumber);
    echo 
    $resultNumber['total'];?>
    All Im getting back is Zero's

  23. #48
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Yes, look at your query:
    PHP Code:
    "select count(Id_Hot) as total from tbl_hotels where ('IdRsrt_Hot="$q['Id_Rsrt'] . "') and (Act_Hot='1') " 
    Now parse it:
    PHP Code:
    "select count(Id_Hot) as total from tbl_hotels where ('IdRsrt_Hot=VALUE_OF_ID_RST') and (Act_Hot='1') " 
    See the problem? That isn't valid syntax in any imaginable way.

    I think you meant to have:
    PHP Code:
    "select count(Id_Hot) as total from tbl_hotels where (IdRsrt_Hot='"$q['Id_Rsrt'] . "') and (Act_Hot='1') " 
    Which when parsed, looks like:
    PHP Code:
    "select count(Id_Hot) as total from tbl_hotels where (IdRsrt_Hot='VALUE_OF_ID_RST') and (Act_Hot='1') " 

  24. #49
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep I can see it, and yes yours works fine.

    Thanks again.

  25. #50
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I seem to be running into a few these now, where there no error, the results are displaying, but the results arent correct for what I need.

    I have had to change the code that outputs the regions from one table so that it also checks another table to see if all of the hotels associated with it are equal to 1.

    PHP Code:
    <?
    $r
    =mysql_query("select DISTINCT Id_Rsrt, Nom_Rsrt, IdCntry_Rsrt, Id_show, Act_Hot from tbl_resorts, tbl_hotels where (tbl_resorts.IdCntry_Rsrt='1') and (tbl_resorts.Id_show='1') and (tbl_hotels.Act_Hot='1') order by Nom_Rsrt ASC");  
    ?>
    Its outputting it correctly, but not doing the final search of (tbl_hotels.Act_Hot='1'), which will mean that no region is displayed with [0] next to it.

    http://devchecksafetyfirst.csf.dcmanaged.com/

    Is there a problem with the code that I havent picked up on.

    Cheers


Bookmarks

Posting Permissions

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