Jump to content

Muddy_Funster

Members
  • Posts

    3,372
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Muddy_Funster

  1. Don't understand what your saying here. I assume it's producing incorrect results? What about SELECT sortBy , webName, value AS titleSort, value AS title, pages.ID, catID, pageName, sortBy FROM pagesCats JOIN pagesIndex ON pagesCats.ID = pagesIndex.catID JOIN pages ON pagesIndex.pageID = pages.ID WHERE subsetOf = '2' AND sortBy IN (select MIN (sortBy) as firstPage FROM pages group by ID) ORDER BY catID That assumes that the ID column in pages is used to identify each user, not each page. If it's not I'll need more accurate information about your tables.
  2. function urlpartencode(&$item, $index) { $item = rawurlencode($item); } $item isn't being returned from the function, so it can't be used elsewhere in the code (hence why it's an invallid argument for the foreach on the line below). you also have a $index in the decleration that's never used inside the function... Your DOM error is because the script either can't find or doesn't have permission to read from the file : "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml"
  3. so this is the problem : <?php foreach ($ph_sets['AHY'] as $ph_set): ?> To the best of my knowledge you can't call a specific array key in a for each, only the array variable it's self: <?php foreach ($ph_sets as $ph_set): ?>
  4. yip : $where[] = array('AND', 'id', 'IN', "(SELECT teacher_id FROM test_cv_tags WHERE skills = '$value1')"); $where[] = array('OR', 'id', 'IN', "(SELECT teacher_id FROM test_cv_tags WHERE skills = '$value2')"); $where[] = array('OR', 'id', 'IN', "(SELECT teacher_id FROM test_cv_tags WHERE skills = '$value3')");
  5. You still need to pass it into the function, functions don't have a global scope. Think of functions like vegas : what happens in a function, stays in a function. You need to explicitly pass variables in and out of functions or it won't work. as for the $_POST['userid'] I'm guessing you don't actualy have a form element that matches that.
  6. you would need to build the $where array using your $_GET varaibles, the $arrVals is the $where array. functions have what's called limited scope. it meens that variables outside them don't affect them, and likewise variables insede them don't affect anything outside them. when we call the function we pass the $where array into it like so buildWhere($where) but in order for the function to know that it's going to have information passed into it, and for the function to be able to address that information we need to declare a varable name that the function can use at the time we are creating it i.e. function buildWhere($arrVals){ so you see, $arrVals is just what the function calls $where - it maps it if you like. I used hard coded values so that it would be stand alone. you could just as easily do the following: $religion = mysql_real_escape_string($_GET['religion']); ... $where[] = array('OR', 'religion', '=', "'$religion'"); //and another ... remember to use double quotes if using variables directly within strings.
  7. ok, let me comment the code and see if that helps: function buildWhere($arrVals){ // declare the function, and the name of the variable within it $out = ''; // set the $out variable to empty foreach($arrVals as $vals){ // loop through each of the contents of the $arrVals array, assiging the content to $vals $out .= "{$vals['0']} {$vals['1']} {$vals['2']} {$vals['3']} "; // add the contnents of each of the $vals array values to the $out variable }//end of loop return $out; // send the $out variable out of the function }//end of function //now we make an array to hold each of the combinations of the where clause that we want to process, then pass in these parts as individual arrays in the order that we want them to be processed. //we build these using the format PREFIX(WHERE AND or OR), FIELD(field from the table that we are using in the comparison), OPERATOR(things like =, LIKE, >, <, IN, HAVING etc), VALUE(the value for the comparison) $where[] = array('WHERE', 'teacher_id', 'IN', '(SELECT candidate_id FROM availability_calendar WHERE (DAY = 19 AND MONTH = 04 AND YEAR = 2012 AND availability = "Available"))'); //assign first part of WHERE clause $where[] = array('AND', 'role_level', '=', '\'\''); //assign another part $where[] = array('OR', 'religion', '=', '\'North East\''); //and another $where[] = array('AND', 'id', 'IN', '(SELECT teacher_id FROM teacher_agencies WHERE agency = \'Education World\')'); //and another $sql = "SELECT * FROM indivdual_teachers "; // start of the SELECT query $append = buildWhere($where); // run the buildWhere function, passing in the $where array we just made above, and assigning the output of that function to the $append variable $sql = $sql.$append; // make the $sql variable = to the combined value of the inital $sql value and the value now in $append echo $sql; // show the value now in $sql Does that make it easier to follow? This is a self contained snippet of code so you can stick it in a new .php file and view the output of $sql on the screen as well if that helps.
  8. why not make a little function to build the WHERE for you? it would make the page much easier to manage. Here's a simple example, this function takes in a 2 tear multidimentional array(so it's an array of arrays) with the 2nd tear havin the following in this order : 'PREFIX' | 'FIELD' | 'OPERATOR' | 'VALUE' function buildWhere($arrVals){ $out = ''; foreach($arrVals as $vals){ $out .= "{$vals['0']} {$vals['1']} {$vals['2']} {$vals['3']} "; } return $out; } $where[] = array('WHERE', 'teacher_id', 'IN', '(SELECT candidate_id FROM availability_calendar WHERE (DAY = 19 AND MONTH = 04 AND YEAR = 2012 AND availability = "Available"))'); $where[] = array('AND', 'role_level', '=', '\'\''); $where[] = array('OR', 'religion', '=', '\'North East\''); $where[] = array('AND', 'id', 'IN', '(SELECT teacher_id FROM teacher_agencies WHERE agency = \'Education World\')'); $sql = "SELECT * FROM indivdual_teachers "; $append = buildWhere($where); $sql = $sql.$append; echo $sql;
  9. How about just selecting the min() or max() sortBy depending on your sort order (still grouping by cat_id)? this will then only return the lowest (or highest) sortBy value for that grouping.
  10. your running a select * inside a while loop, that's a way bigger problem than not getting any results back. Fix your code, you should only need a single query run once. If you can't manage it yourself post up an exact breakdown of what you are trying to acomplish and someone will help you out. Once you fix that your results problem wont even factor.
  11. please post code inside code tags, and for the love of whichever celestial being you happen to worship, post what the actual error is!
  12. this is a CSS issue, not PHP. Have you tried using display:inline-block?
  13. You need to use either Javascript or AJAX
  14. so how did you get on with that code?
  15. and what does "it doesn't work" actualy translate to?
  16. Well I'm off for the night, but I'll leave you some stuff to have a play with: first up, make a new file and call it "mstr_ref.inc". in it have the following code (changing the credentials to your own): <?php define('__HOST', 'localhost'); //localhost = database host name (normaly this won't need changing) define('__USER', 'xxx'); //xxx = database username define('__PASS', 'xxx'); //xxx = database password define('__DEF_DB', 'xxx'); //xxx = database name $con = mysql_connect(__HOST, __USER, __PASS) or die(mysql_error()); $db = mysql_select_db(__DEF_DB, $con) or die (mysql_error()); ?> then add this code to the top of the idx.php: <?php require_once 'mstr_ref.inc'; ?> this now meens that the idx.php can connect to the database. which is good, because next we want to use the following piece of code to create the locations element for the form. This way each time a new location gets added to the database it will show in the list without any other action needed. using what you've picked up from the bedrooms and prices you should be able to insert this bit of code to get the locations displaying out of the database (remember you will need to have them in the database first of all) Note: the <select> is being echoed from within the code this time, so watch out for that. <?php $locationSql = "SELECT id, area_name FROM Locations GROUP by area_name"; $locQry = mysql_query($locationSql) or die (mysql_error()); echo "<select name=\"areas\" multiple=\"multiple\" size\"=5\" style=\"width:150px;\">"; while ($location = mysql_fetch_assoc($locQry)){ echo "<option value=\"{$location['id']}\">{$location['area_name']}</option>"; } echo "</select>"; ?> also, we'll use the catagories table for storing the types "house" and "flat" in, so you can use the type column for semi, bungalow etc. have a shot scripting the Property Type <select> box to read from the catagories table and display the results. Everything you need is in the code here, so it should be easy enough. I'll check back in in the morning and work on scripting up some more stuff. Good Luck
  17. yeah, sorry, that's the screwed up loop version of the code you'll need to change to this: <select name="min price"> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice =( $minPrice+ 10)){ if ($minPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value\"$minPrice\">£$minPrice</option>"; } } ?> </select> The rest of the page should render after that, the problem is that the screwed up version runns an infinate loop, so the page gets jammed there.
  18. looks good, what do you see if you go to your idx.php (or whatever you called it)?
  19. ok, revised code, buggered the loop on the price select. <select name="min bedrooms"> <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){ if ($minRooms == 0){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value\"$minRooms\">$minRooms</option>"; } } ?> </select> <select name="min price"> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice =( $minPrice+ 10)){ if ($minPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value\"$minPrice\">£$minPrice</option>"; } } ?> </select> The code replaces all the html between the opening and closing <select> so: <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <select name="min bedrooms"> <?php // ***IN HERE*** ?> </select> to
  20. ok, make a copy of index.html and name it something along the lines of idx.php, this will give us a safe area to work in. Once that's done have a look at these code snipits <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){ if ($minRooms == 0){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value\"$minRooms\">$minRooms</option>"; } } ?> </select> ?> <select name="min price" ...> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice+10){ if ($minPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value\"$minPrice\">£$minRooms</option>"; } } ?> </select> They are going to generate your dropdowns for price and bedrooms. I've included the start of each <select> so you can see exactly where they will go. you'll need to add in copy's for the max versions as well, just make sure and change the min to max, you don't need to re-declare the $xxxLimit as it's going to be the same and isn't changed in the loops. Doing it this way makes the source of the page you see is shorter and easier to maintain. so if in the future you want to add a property that's 600k, or a house with 8 bedrooms, you don't need to add all those lines manualy to keep continuity, just change a number and your done.
  21. type was actualy to hold house or flat, for the search to filter on. There's nothing to search against type of house (yet!) - so we don't need a field for that information - but don't worry, we can cover that another time. anything else about the tables you want to cover or are we ready to start editing index.php? p.s. I'm pretty sure I suck at explaining things, that's why I keep checking
  22. not hugely important, but you should set it to your local colation, you should be able to change that with the settings in phpMyAdmin. I just havn't set anything on this computer yet because I only use it for inital dev work. So you get how all the tables are going to interact and hold the info for each property listing? category_id -- is going to be the id from the category table that represents the area name that the property is in. market_type -- is going to hold eather Sale, Rent, Rent To Buy that sort of thing pay_interval -- if for rental properties and will be things like 4 - weekly, per calander month, weekly, etc. making sense so far?
  23. yeah, just copy and past into that box and run it. then you'll naeed to take some time and look over the tables, make sure you can see what's going on before we move on.
  24. yip, like that
  25. OK, multiple="multiple" should stay, add in name="area" as well as that, the multiple="multiple" makes it so you can select multiple entrys from the list. next step - better database table structure: CREATE TABLE `catagorys` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `cat_name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `images` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `property_id` bigint(20) NOT NULL, `image_path` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `locations` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `area_name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `property` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `location_id` bigint(20) DEFAULT NULL, `catagory_id` bigint(20) DEFAULT NULL, `type` varchar(255) DEFAULT NULL, `bedrooms` int(11) DEFAULT NULL, `bathrooms` int(11) DEFAULT NULL, `receptions` int(11) DEFAULT NULL, `parking` varchar(255) DEFAULT NULL, `garden` varchar(255) DEFAULT NULL, `market_type` varchar(255) DEFAULT NULL, `asking_price` decimal(13,2) DEFAULT NULL, `pay_interval` varchar(255) DEFAULT NULL, `summary` varchar(255) DEFAULT NULL, `full_description` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; run that against your database using the Query tab of whatever it is that you access it with (I'm assuming phpMyAdmin as I didn't take a close look at the images)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.