Jump to content

Canman2005

Members
  • Posts

    669
  • Joined

  • Last visited

    Never

Posts posted by Canman2005

  1. Basically what I want to do is, if I pass

     

    (1,2)

     

    in my QUERY, I want it to only return `staff` values from the `classes` table where it matches every ID passed.

     

    So with my table

     

    `classes` (`id`, `class`, `staff`)
    (3, 1, 1),
    (4, 2, 1),
    (5, 2, 2);

     

    If I ran (1,2) in my QUERY, it would only return `staff` id 1 from the above table, because only `staff` id 1 has `class` values "1" and "2" in the above table.

     

    If I ran just (2), then it would return, ID numbers 1 and 2, because both contain `class` values "2"

     

    If I ran (1,2,10), then it would return nothing, as non of the staff ID's have a matching "1","2" and "10" IDs

     

    I might not be explaining this very well

     

    Does it make any sense?

  2. But even if I run

     

    SELECT s.name FROM staff s JOIN classes c ON s.id = c.staff WHERE c.class IN (1,3,10) GROUP BY c.staff

     

    it finds a result, where as it should not find anything, as id 3 and 10 don't exist under the "class" field in the "classes" table.

     

    If the QUERY was

     

    SELECT s.name FROM staff s JOIN classes c ON s.id = c.staff WHERE c.class IN (1,2) GROUP BY c.staff

     

    then it should find something, as id 1 and 2 exist

     

    does that kind of make any sense?

     

    any help would be great

     

    thanks

     

    ed

  3. Hi all

     

    I have a series of tick boxes on my PHP form, they look like

     

    <input name="cat" value="Math" type="checkbox">
    <input name="cat" value="Art" type="checkbox">
    <input name="cat" value="Dance" type="checkbox">

     

    if I submit those fields, then my URL looks like

     

    find.php?key=&cat=Math&cat=Art&cat=Dance

     

    For search engine reasons, whats the best way in Javascript to Re-Write the URL so that it's SEO friendly URL

     

    I was thinking when the form is posted, to re-write that URL so that it looks like

     

    find.php?key=&cat=Math%7CArt%7CDance

     

    So it basically only shows 1 "cat=" and any other are replaced with "%7C" to allow me to seperate the vars with PHP

     

    Any advice would be top

     

    Thanks

     

    Ed

  4. My new table structure looks like

     

    `classes` (`id`, `class`, `staff`)
    (1, 0, 0),
    (2, 0, 0),
    (3, 1, 1),
    (4, 2, 1),
    (5, 2, 2);
    
    `staff` (`id`, `name`)
    (1, 'Dave'),
    (2, 'Sarah'),
    (3, 'Brian');

  5. Sure, I have changed my db fields a little, but the QUERY I use is

     

    SELECT s.name FROM staff s JOIN classes c ON s.id = c.staff WHERE c.class IN (1,3,10) GROUP BY c.staff

     

    basically I only want it to return a result if "c.class" equals all the values passed, so it must match ID 1,3,10.

     

    At the moment it returns a result if any of ID (1,3,10) exist, I only want it to return a result if all the IDs exist

     

    Can anyone help?

     

    Thanks very much

  6. Hi

     

    I tried "IN" but it seems to return a result if just one of the ID's passed in the URL exist in the table.

     

    How can I make sure it only returns rows which match every ID passed in the URL

     

    Thanks guys

  7. I managed with

     

    SELECT u.id, l.type1,l.type2,l.type3, (select Count(*) from log l WHERE l.type1 = 1 || l.type2 = 1) AS tot1,(select Count(*) from log l WHERE l.type3 = 1) AS tot2 FROM log l JOIN users u ON l.userid = u.id WHERE u.place = 1 GROUP BY u.id

     

    to output

     

    id   type1   type2   type3   tot1   tot2
    1   1           1         1           233   244
    2   1           1         1           200   201
    3   1           1         1           123   143
    4   1           1         1           89      99
    5   1           1         1           2        4

     

    which is excellent

     

    is it possible to add up "tot1" and "tot2" and output them as "total"

  8. Hi all

     

    Wonder if someone can help.

     

    I have the following QUERY which contains a COUNT statement

     

    SELECT u.id , COUNT(*) AS `total` FROM log l JOIN users u ON l.userid = u.id WHERE u.place = 1 GROUP BY u.id ORDER BY `total` DESC

     

    this works great and returns a result such as

     

    1   877
    2   455
    3   232
    4   199

     

    but is it possible to do a WHERE statement in my COUNT, so it would look something like

     

    COUNT(*) WHERE l.type1 = 1 || l.type2 = 1

     

     

    but then also include another COUNT statement which would look like

     

    COUNT(*) WHERE l.type3 = 1

     

    but multiple the above COUNT number by 2, I know it's totally wrong, but something like

     

    COUNT(*) WHERE l.type3 = 1 * 2

     

     

    but then ADD the numbers from the 1st COUNT and 2nd COUNT together and output them as the

     

    ORDER BY `total` DESC

     

    value

     

    so it would look something like

     

    1   ((COUNT 2 * 2) + COUNT 1)
    2   ((COUNT 2 * 2) + COUNT 1)
    3   ((COUNT 2 * 2) + COUNT 1)
    4   ((COUNT 2 * 2) + COUNT 1)

     

    Any help would be great, been trying to crack this for the last few hours but having no luck

  9. Hi all

     

    I have a table called `classes` which looks like

     

    'id','name'
    1,English
    2,French

     

    I also have a table called `staff` which looks like

     

    'id','name','class'
    1,Dave,2
    2,Sarah,2
    3,Brian,1

     

    in my URL string I am using

     

    staff[]=2&staff[]=1

     

    how can I write a QUERY to return a list of all `classes` which staff are attending.

     

    In my example (staff[]=2&staff[]=1) it would return just

     

    French

     

    because in the URL string I am geting "staff ID 1" (staff[]=1) and "staff ID 2" (staff[]=2) which are Dave & Sarah which both attend the "French" class

     

    but if for example I passed the URL string

     

    staff[]=2&staff[]=5

     

    it would return nothing, as there is no staff with ID number 5 (staff[]=5)

     

    Any help would be brill

     

    thanks

     

    ed

  10. Hi All

     

    I wonder if someone can help me out.

     

    Basically I have 3 tables, they are

     

    `products` , `product_categories`, `categories`

     

    So the tables might for example look like

     

    `products` (`id`,`title`)
    `1`,`iphone`
    `2`,`microsoft mouse`

     

    `categories` (`id`,`title`,`level`,`parentid`)
    `1`,`mouses`,`1`,`0`
    `2`,`microsoft`,`2`,`1`
    `3`,`mp3`,`1`,`0`
    `4`,`apple`,`2`,`3`
    

     

    So `level` basically says that `mouses` is a top level category and `microsoft` is a sub category of `mouses` and `mp3` is a top level category) and `apple` is a sub category of `mp3`

     

    `product_categories`
    `id`,`product_id`,`category_id`
    `1`,`1`,`4`
    `2`,`2`,`2`

     

    hopefully that makes sense, but it's basically saying that product id number 1 (iphone) belongs to category number 2 (apple) and product number 2 (microsoft mouse) belongs to category number  (microsoft)

     

    I then have a series of tick boxes through PHP and it outputs in HTML something like the following

     

    <input name="category1[]" value="1">Mouses

    <input name="category2[]" value="2">Microsoft

    <input name="category1[]" value="3">MP3

    <input name="category2[]" value="4">Apple

     

    Now at the moment I run a QUERY which looks like

     

    SELECT * FROM products p JOIN products_categories pc ON p.id = pc.product_id WHERE (pc.category_id = 2 || pc.category_id = 4)

     

    which returns me a result, perfect.

     

    I wonder though, how easy is it to further that QUERY and if I select "Mouses" (ID 1) tickbox, then I would find a result, even though I don't store the top level category id (ie: 1 = Mouses) within the `product_categories` table.

     

    My only option is to also store the top level category id (ie: 1 = Mouses) within the `product_categories` table.

     

    Is there a way without me doing this?

     

    Thanks in advance

     

    Dave

  11. Hi all

     

    I have the following QUERY

     

    $sql = "SELECT bm.who, pl.bmid , COUNT( * ) AS `score` FROM log pl JOIN usr bm ON pl.bmid = bm.id GROUP BY pl.bmid ORDER BY `score` DESC";
    $show = @mysql_query($sql,$connection) or die(mysql_error());
    while ($row = mysql_fetch_array($show))
    {
    print 'Total: '.$row['score'];
    }

     

    This works great.

     

    My question is, how can I get the previous`score`, so I can do something like

     

    Total: 100

    Previous:

     

    Total: 75

    Previous: 100

     

    Total: 50

    Previous: 75

     

    Total: 25

    Previous: 50

     

    I tried doing it using

     

    LIMIT

     

    but I can only get the next rows score and not the previous score.

     

    Can anyone help?

     

    Thanks tons in advance

     

    Dave

  12. Dear All

     

    I have a standard page which has a HTML form doing a "POST" method.

     

    What I want to do is have 3 buttons on my page doing the following

     

    Button 1;

    Posts data as normal

     

    Button 2:

    Posts data to an alternative URL (pageone.php) with the target frame being an iframe called "iframeone"

     

    Button 3:

    Posts data to an alternative URL (pagetwo.php) with the target frame being an iframe called "iframetwo"

     

     

    I've looked all over and I cannot find anything like this, which I thought I would be able to find tons.

     

    Can anyone help?

     

    Thanks very much

     

    Dave

  13. Hi all

     

    I have the following in my .htaccess file

     

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule \.(gif|jpeg|jpg|png)$ functions/watermark_wrapper.php [QSA,NC]

     

    at the moment this affects all image files

     

    Is it possible to have it just take effect on images within the folder ROOT/myphotos and any sub folders within that

     

    Thanks in advance

  14. Hi all

     

    Wonder if anyone can help.

     

    Basically I have a bunch of form fields which look like

     

    <input name="fullname" type="text">
    <input name="1-value[]" type="text" value="Apple">
    <input name="4-value[]" type="text" value="Microsoft">
    <input name="6-value[]" type="text" value="IBM">
    <input name="12-value[]" type="text" value="1to1">

     

    sometimes there is just 1 field, sometimes 4 fields and sometimes 20 or so fields.

     

    what I want to do is run an

     

    INSERT INTO

     

    for each form field that exists that has "-value[]" set as its "name=" tag

     

    but also, I want to be able to extract 2 things, firstly the numeric value which is defined before the "-value[]" and also the actual value of each form field (ie: IBM \ Apple).

     

    This means I would then be able to do something like

     

    INSERT INTO `items` SET `idnumber`="[b]NUMERIC VALUE[/b]", `value`="[b]FIELD VALUE (ie: IBM \ Apple)[/b]"

     

    for each form field returned.

     

    Can anyone advise?

     

    Thanks very much

  15. Hi all

     

    I have a ASP problem i'm wondering if anyone can help with.

     

    I have a form which has the following field on it

     

    <input type="file" NAME="image2">

     

    I then have the following code to upload the image

     

    	dim filename2
    filename2 = UploadRequest("image2").Item("filename2")
    filename2 = Right(filename2,Len(filename2)-InstrRev(filename2,"\"))
    if not filename2="" then	
    	if instr(ucase(filename2),".GIF")>0 or instr(ucase(filename2),".JPG")>0 or instr(ucase(filename2),".PNG")>0 then
    		UploadPath=server.mappath("../prod_images/")&"\"
    		if not filename2="" then
    			if instr(ucase(filename2),".GIF") then
    				filename2=imageID &"-2.gif"
    			elseif instr(ucase(filename2),".JPG") then
    				filename2=imageID &"-2.jpg"
    			elseif instr(ucase(filename2),".PNG") then
    				filename2=imageID &"-2.png"
    			end if
    			UploadPathFN=UploadPath&filename2
    			ImgKBSize=savefile("image2",UploadPathFN)/1024
    			if ImgKBSize>250 then
    				deleteFile(UploadPathFN)
    				msg=msg &"
    You can only upload images under 250kb."
    			end if
    		end if	
    	else
    		msg=msg &"
    You can only upload *.gif, *.jpg and *.png files."
    	end if
    end if

     

    but for some reason this has stopped working and I cannot figure out why.

     

    Can anyone figure out why this is happening?

     

    Thanks everyone in advance

  16. HI all

     

    I have been battling with making a SELECT funtion and wonder if anyone can help.

     

    To pull the function, i'm using

     

    $data = select("members",array("id"),"id='1'");
    foreach($data as $d){
    print $d["id"];
    }
    

     

    and the function code is

     

    function select($table, $fields=array(), $where=NULL, $limit=NULL, $order=array(), $group=array())
    {
    $string .= "SELECT ".implode(", ", $fields)." FROM ".$table;
    $string .= ($where) ? " WHERE ".$where : NULL ;
    $string .= (count($group) > 0) ? " GROUP BY ".implode(", ", $group) : NULL ;
    $string .= (count($order) > 0) ? " ORDER BY ".implode(", ", $order) : NULL ;
    $string .= ($limit) ? " LIMIT ".$limit : NULL ;
    $result = mysql_query($string);
    while($row = mysql_fetch_array($result))
    {
    $row = array_map('stripslashes', $row);
    }
    }

     

    Can anyone help?

     

    Thanks in advance

     

    Dave

×
×
  • 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.