Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0

    Angry Function and Loop Problems


    Hi,

    I am making a simple search result page and for some reason, I am having a day long brainfart and I need some help as to why my code isn't working at all. I want first to retrieve the results using a query, and then count them. Then, by setting the variable $display_limit to 20, I want to make it so that only 20 results are shown, and then a link to the next page with the next 20. Next I want to order the results in order of their package number, set in a different table than the one that contains the search results. The two tables are linked by two different id's, labeled PROP_ID ($prop_id) and REGISTRATION_ID ($id, same as $user_id). For some reason I cannot figure out how to do this easily because once I break it down, I realize that the one thing that will make it work will change everything. If you need any more explination as to how it is supposed to work, just ask. Here is the code that contains the function, and any other stuff:

    PHP Code:
    <?php
    if ($_SESSION['PAGE_NAME'] == "searchpage.php") {
        
    $query2 "SELECT * FROM prop_info WHERE CONTINENTS='North America' AND COUNTRY='United States' AND STATE='$statefull' AND DISPLAY='yes'";
    } else {
        
    $query2 "SELECT * FROM prop_info WHERE CONTINENTS='$con_name' AND COUNTRY='$country_name$aa AND DISPLAY='yes'";
    }
    $result2 mysql_query($query2);
    $display_limit '20';
    $items_count mysql_num_rows($result2);
    if(isset(
    $_GET['page_count'])) {
        
    $page_count $_GET['page_count'];
    } else {
        if(
    $items_count $display) {
            
    $page_count ceil ($items_count/$display_limit);
        } else {
            
    $page_count 1;
        }
    }
    if(isset(
    $_GET['start'])){
        
    $start $_GET['start'];
    } else {
        
    $start 0;
    }
    $query $query2." LIMIT $start,$display_limit";
    echo 
    $query;
    $result mysql_query($query);
    //------------------- To show Search Result ------------------------------------
    function view_property() {
        global 
    $query;
        
    $query $GLOBALS["query"];
        
    $result mysql_query($query);
        
    $int 0;
        
    $prop_array = array();
        
    $user_array = array();
        while (
    $rw mysql_fetch_array($result)) {
            
    $user_array[$int] = $id $rw[0];
            
    $prop_array[$int] = $prop_id $rw[17];
            
    $int++;
        if (
    $int != 0) {
            
    $count count($prop_array);
    //===========================  Platinum  =================================//
            
    for ($int_1 0$int_1 $count$int_1++) {
                
    $query_pay "SELECT * FROM payment WHERE PROP_ID=$prop_id AND USER_ID=$id AND PAY_STATUS='true' ORDER BY PACKAGE ASC";
                
    $result_pay mysql_query($query_pay);
                while (
    $rw2 mysql_fetch_array($result_pay)) {
                    
    //$prop_id = $rw[18];
                    //$id = $rw[0];
                    
    $package $rw2[9];
                }
                
    $num_pay 0;
                
    $query_2 "SELECT * FROM prop_info WHERE REGISTRATION_ID=$id AND PROP_ID=$prop_id";
                
    $result_2 mysql_query($query_2);
                
    $int 0;
                while (
    $row mysql_fetch_array($result_2)) {
                    
    $int++;
                    
    $query1 "SELECT * FROM images_info WHERE REGISTRATION_ID=$id AND PROP_ID=$prop_id";
                    
    $result1 mysql_query($query1);
                    
    $a 0;
                    while (
    $row1 mysql_fetch_array($result1)) {
                        
    $a++;
                        
    $image_name $row1[1];
                    }
                    if (
    $a == 0) {
                        
    $image_name "imgnotavailable.jpg";
                    }
                    if (
    $int >= $start && $int <= $display_limit) {
                        if (
    $package == "1") {
                    
    ?>
                    <tr class="boldrow">
                    <td width="101" class="first">
                    <a href="view_detail_property.php?prop_id=<?php echo $prop_id?>&cp=<? echo $c_page;?>"><img border="0" src="photo/<?php echo $image_name?>" width="100" height="63"></a></td>
                    <td width="111">
                    <p align="center"><font size="2"><?php  echo $row[2]; ?></font></p>
                    <p align="center"><font size="2">
                    <a href="view_detail_property.php?prop_id=<?php echo $prop_id?>&cp=<? echo $c_page;?>">Premium Property Details</a></font></td>
                    <td width="117">
                    <p align="center"><font size="2"><?php  echo $row[1]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[9]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[10]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[11]; ?></font></td>
                    <td width="55">
                    <p align="center"><font size="2"><?php echo $row[5]; ?></font></td>
                    <td width="61" class="last">
                    <p align="center"><font size="2"><?php echo $row[7]; ?></font></td>
                    </tr>
                    <tr>
                    <td width="100%" height="10" colspan="8">&nbsp;</td>
                    </tr>
                    <?php
    //================================== Gold ==================================//
                        
    } elseif ($package == "2") {
                    
    ?>
                    <tr class="gold">
                    <td width="101" valign="middle" align="center">
                    <a href="view_detail_property.php?prop_id=<?php echo $prop_id?>&cp=<? echo $c_page;?>"><img border="0" src="photo/<?php echo $image_name?>" width="100" height="63"></a></td>
                    <td width="111">
                    <p align="center"><font size="2"><?php echo $row[2]; ?></font></p>
                    <p align="center"><font size="2">
                    <a href="view_detail_property.php?prop_id=<?php echo $prop_id?>&cp=<? echo $c_page;?>">Gold Property Details</a></font></td>
                    <td width="117">
                    <p align="center"><font size="2"><?php echo $row[1]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[9]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[10]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[11]; ?></font></td>
                    <td width="55">
                    <p align="center"><font size="2"><?php echo $row[5]; ?></font></td>
                    <td width="61">
                    <p align="center"><font size="2"><?php echo $row[7]; ?></font></td>
                    </tr>
                    <tr>
                    <td width="100%" height="10" colspan="8">&nbsp;</td>
                    </tr>
                    <?php
    //============================== Silver ===================================//
                        
    } elseif ($package == "3") {
                    
    ?>
                    <tr>
                    <td width="101">
                    <a href="view_detail_property.php?prop_id=<?php echo $prop_id?>&cp=<? echo $c_page;?>"><img border="0" src="photo/<?php echo $image_name?>" width="100" height="63"></a></td>
                    <td width="111">
                    <p align="center"><font size="2"><?php echo $row[2]; ?></font></p>
                    <p align="center"><font size="2">
                    <a href="view_detail_property.php?prop_id=<?php echo $prop_id?>&cp=<? echo $c_page;?>">Property Details</a></font></td>
                    <td width="117">
                    <p align="center"><font size="2"><?php echo $row[1]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[9]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[10]; ?></font></td>
                    <td>
                    <p align="center"><font size="2"><?php echo $row[11]; ?></font></td>
                    <td width="55">
                    <p align="center"><font size="2"><?php echo $row[5]; ?></font></td>
                    <td width="61">
                    <p align="center"><font size="2"><?php echo $row[7]; ?></font></td>
                    </tr>
                    <tr>
                    <td width="100%" height="10" colspan="8">&nbsp;</td>
                    </tr>
                    <?php
                        
    }
                    }
                }
            }
        }
    }
    }
    //databaseClose();
    ?>
  2. #2
  3. Back and Forth.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Earth
    Posts
    491
    Rep Power
    0
    For some reason I cannot figure out how to do this easily because once I break it down, I realize that the one thing that will make it work will change everything.
    It seems like you already know what the problem is, then?

    What is the one thing that you think will make it work?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    Having my friend come over and coding it from scratch with me. But I was wondering if it was simple enough for tonight.
  6. #4
  7. Back and Forth.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Earth
    Posts
    491
    Rep Power
    0
    Could you upload a script to a server, so we can see it in action? Or explain what is going wrong with it? What is happening when you execute the code?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    Yeah sorry its here. I think the problem is the different loops and the queries that go with them. I think I am just tired of working on it.
  10. #6
  11. Back and Forth.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Earth
    Posts
    491
    Rep Power
    0
    In your code - your not calling view_property() function.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    Yeah I actually am, I have an include and then call the function, but I decided not to put that in because I thought it was irrelavent.
  14. #8
  15. Back and Forth.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Earth
    Posts
    491
    Rep Power
    0
    have you got error_reporting(E_ALL); at the top of your code?

    Comments on this post

    • KillaH425 agrees : Helpful
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    I do now! Let me get back to you with an update after I debug those errors.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    I fixed most of the errors, but now I am seeing doubles (I am assuming a double loop, but I can't really figure it out). Also, it isn't querying right at all, the ones that are supposed to be on the top aren't (it isn't sorting by what I wanted, I am assuming that query isn't working, which is kind of where my problem began). Also, $package (package number I am sorting by; ascending) is at the top. Check here again
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    What I really want to know is how to get the query that belongs on the outside of the function to work as if it was inside the function, as I can't call its variables (I made global one, but it didn't really do much) and thats where my problems begin and end really. I need to be able to take some of the stuff before the function (where the function is defined, so to speak) and use it in the function.
  22. #12
  23. Back and Forth.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Earth
    Posts
    491
    Rep Power
    0
    I would pass the query string $query to the function....

    PHP Code:

    $query 
    $query2." LIMIT $start,$display_limit"
    view_property$query );

    function 
    view_property$query ) {
           
    // perform mysql_query within this

  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    Won't that call the function right there? I don't want to call the function there, as it gets called in the parent file. I will try it, giving you the benefit of the doubt considering I have not really progressed today.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    23
    Rep Power
    0
    Yeah it ended up bombing the thing like I expected. I think I know what I have to do to fix this, move all the code before the function to the parent file (its currently in an included file) and then just do that and pass the variable as an argument. I will wait until early tomorrow to do this though, as I am now hooked on making something else. Thank you very much for your help and I will get back to you with an answer.
  28. #15
  29. Back and Forth.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Earth
    Posts
    491
    Rep Power
    0
    Best of luck with it all.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo