Jump to content

prw

Members
  • Posts

    16
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

prw's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [*]I'm selecting all columns as I wish to return every column for the first query, and just the page_url of its parent for the second query. From my understanding and experience you have to select the exact same columns with both queries or the UNION will break and the code will through up a MySQL error. [*]It's the same table, so its the same amount of columns. [*]There is no MySQL error, just the second SELECT query isn't returning the page_url column AS parent_url which is what I desire.
  2. I'm trying to merge two queries (as from what I understand this is faster than if it were to be 2 separate queries - correct me if I'm wrong). It's a table which stores website pages with both parent and child pages. There's an ID (parent_id) specified for child pages of who its parent is, but I need a second query in order to lookup the ID of its parent and determine what its parents URL (page_url) is. My query at the moment doesn't return parent_url where I've specified it to right after the UNION. What am I doing wrong? SELECT *, page_url, parent_id AS get_parent_id FROM pages WHERE page_url='$page' AND child='1' UNION SELECT *, page_url AS parent_url, parent_id FROM pages WHERE id='get_parent_id'
  3. Ah right of course, totally forgot that I set $b and $c to be empty, changing the isset's fixed my problem. Thanks for pointing it out.
  4. I keep get the following warning whilst using the following function which I wrote. Is there a way of getting rid of the warning? I'm aware I can just turn off error_reporting to not see the warning, but just wondering if there's a way of fixing it. function contains($value, $a, $b = '', $c = '') { if (isset($b) && isset($c)) { if (stristr($value, $a) || stristr($value, $b) || stristr($value, $c)) return true; } elseif (isset($b)) { if (stristr($value, $a) || stristr($value, $b)) return true; } else { if (stristr($value, $a)) return true; else return false; } }
  5. Managed to find a solution that works perfectly: http://stackoverflow.com/questions/4259225/selecting-records-in-order-of-parent-id SELECT Concat(If(isnull(p2.page_name),"",Concat("/",p2.page_name)),"/",p1.page_name) AS `generated path`, p2.page_name AS parent, p1.* FROM pages p1 LEFT JOIN pages p2 ON p1.child_id = p2.id ORDER BY `generated path` Thanks for the help.
  6. Ah no, I don't wish the results to be a adjacent. I guess my dash put you off a bit there, sorry. Just put that they to make them seem separate from the parent. Just want it listed as a normal vertical row, like so: http://cl.ly/6R5g
  7. You are correct to assume there's only two levels. So a child cannot be within another child. Your query doesn't seem to work how I want the rows to show though. I only see Parent 1, and Parent 2 twice whereas I want to see the Childs below the parents with no duplicate records.
  8. I've searched around and cannot find a solution that works perfectly for this. My MySQL structure: idchildchild_idpage_name 100Parent 1 215Child 1 311Child 2 415Child 3 500Parent 2 Desired order of results: Parent 1 - Child 2 Parent 2 - Child 1 - Child 3 My MySQL query at the moment, which of course doesn't order the results as I desire: SELECT * FROM pages GROUP BY id ORDER BY FIELD(child, '1', '0') DESC, id DESC How would I go about ordering them correctly?
  9. I wish to order my results by its occurrence inside the $status array. Basically all of the results with the status 'New' are to be listed first, then the results with the status Today, Tomorrow, Soon and so on. Is this possible, or is there alternatively a different approach to ordering my results how I desire? $status = array('New', 'Today', 'Tomorrow', 'Soon', 'Future', 'Complete'); $display->get_results("SELECT * FROM todo ORDER by status DESC");
  10. I'm trying to make a function which will display the top X results of the row Y which I set, for this instance I'm using the row browser and the top 5 results from my table statistics, the where is just to eliminate Search Bot results from showing up. I also want it to return the count of the amount of rows as well. So say there was 10 results for the browser 'Safari', then it would return the count of 10 for that result as well as the result itself. $display->show_list('statistics', 'browser', '5', 'WHERE browser!=\'Search Bot\''); Here is my function. I'm cleaned it up a bit to remove certain checks and outputs if the query were to fail, etc. function show_list($table, $row, $limit = 5, $where = NULL) { $item = mysql_query("SELECT DISTINCT $row FROM $table $where LIMIT $limit"); $result = array(); while ($fetch = mysql_fetch_array($item)) { $result[] = $fetch; } return $result; } Basically, how would I go about making it count the amount of rows for the row I've set, and then to output that along side the result?
  11. I'm somewhat new to OOP PHP, and I'm still learning, but basically I want searchcolumns() to set which MySQL columns that it'll search inside but I don't know where to go from what I've already coded. Here's the basic input to be sent to my classes file: $getusers = new database; $getusers->search($_GET['search']); $getusers->searchcolumns('username','account','email'); And to put it simple, I need my $where variable to output this: $where .= "(username LIKE '%$search%' OR account LIKE '%$search%' OR email LIKE '%$search%')"; Except replacing the already set columns with the ones that I assigned in the searchcolumns() array, and then adding an OR string if there's more than 1 column set. Here's the code as I have it at the moment, for obvious reasons, it doesn't work how I want it to: // Search columns function searchcolumns($columns) { $this->column = explode(", ", $columns); } // Search results function search($search) { $search = ($_POST['search']); if (isset($_GET['search']) && strlen($_POST['search']) > 1) { $searchresult = explode(" ", $search); $where = "WHERE"; foreach ($searchresult as $key => $search) { $where .= "($this->column LIKE '%$search%')"; if ($key != (sizeof($searchresult) - 1)) $where .= " AND "; } $this->where = $where; } } Sorry if this has been somewhat confusing to explain, but hopefully someone understands what I'm trying to achieve.
  12. Ah perfect, I never thought of doing it like that. This is what I used instead: $checkemail = mysql_query("SELECT email FROM users WHERE email='$email' AND id!='$id' LIMIT 1"); Thanks!
  13. Hello - I've come to an issue with something I'm working on and have searched around with no luck. When editing user accounts I want it to not be able to change the e-mail address into existing ones on other rows, but when submitting the form it takes into account that this particular rows email address is the same as the one which was sent via $_POST and throws up the error. The desired behaviour I want is for it to ignore the ID of the row which was posted, but take into account every other row. Here's the code as it stands at the moment: $email = $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); } if (mysql_num_rows($checkemail) > 0) { return $this->error("The e-mail address you provided is already associated with an account."); }
  14. Ah that worked. How such a small change can make a difference! Thanks for the help.
×
×
  • 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.