Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 33
  1. #16
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    The get has to match the querystring. So with a url like: showproduct?productid={$row['part_num']}, that should give you a link like showproduct?productid=45. The querystring here is the productid, so the $_GET would need to check for $_GET['productid'] and not $_GET['partnum']. This key carries no meaning on its own btw, so it doesn't really matter what it is called; they just have to match. You could call it ?se553k35k6=45 if you really wanted to, and find that in the $_GET['se553k35k6'] offset.
    Also, you seem to be missing the extension on the script name. Although not necessarily an issue, typically you'll have showproduct.php?productid=x and not just showproduct?productid. I can't say its wrong though since it could be using rewrite rules, but generally with that I'd expect to see /showproduct/x where x is the productid and is rewritten by the rewrite engine.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  2. #17
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Really banging my head on the desk here on what Im doing wrong

    Im testing it on a part number with url productid=YY-2006H05

    If I echo out the productid, but simply doing echo $_GET["productid"];
    I get the value YY-2006H05
    which is great

    However, when I echo out the $id from
    $id = isset($_GET['productid']) ? (int)$_GET['productid'] : 0;
    if ($id > 0)

    I just get 0, when I would have expected this to result in YY-2006H05


  3. #18
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No, I cast since I assumed an actual number. You can't cast 'YY' into a number, so it effectively casts it to 0.
    That instead is a string. You'll need to filter it through an escape sequence:
    PHP Code:
    $id = isset($_GET['productid']) ? mysql_real_escape_string($_GET['productid']) : ''
    Should do what you need.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  4. #19
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    This is definitely out of my territory of basic knowledge now. I will give it a go, but need to read in to what this means as well, any suggestions on what to best read up on to understand what you have done here?

  5. #20
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  6. #21
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Got this working a treat now, thanks Fou-Lu

    I guess I need to get round to looking and learning sqli next!!

    One thing I want to add to this page is a summerised table at the bottom of the product page with a range of product that fall in to a size range to the product being views.

    Can I there take the [size] data of the product, and create a new sql query and html table that displays say + and - 50 meters in size.

    Is it possible to do maths with sql?

    Maybe
    $result = mysql_query("SELECT * FROM products WHERE size < $row[size] +50 AND size < $row[size] - 50");

  7. #22
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ok, figured out that this is done on the php level, so I wrote the below but its dosnt seem to be adding on the variable

    $part_size = $row[size];
    $first_number = $part_size + 20;
    $second_number = $part_size - 20;

    anything obvious Ive done wrong here

  8. #23
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts


    Am I doing something wrong with the operators here :

  9. #24
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you need to use brackets.
    PHP Code:
    $first_number = ($part_size 20); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  10. #25
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hmmmm, just tried that but it doesnt seem to be working.

    I seem to be getting a value of 400 for each of the calculations


    Code:
    $part_size = $row[size];
    $first_number = ($part_size + 20);
    $second_number = ($part_size - 20);

  11. #26
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Add:
    PHP Code:
    var_dump($part_size$first_number$second_number); 
    At the end of the code you have there and post that result.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  12. #27
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi, I added the code you mentioned, and I get the following result


    string(4) "20.0" float(40) float(0) var_dump20.0400


    Code:
    $part_size = $row[size];
    $first_number = ($part_size + 20);
    $second_number = ($part_size - 20);
    var_dump($part_size, $first_number, $second_number);
    
    
    echo var_dump;

  13. #28
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    These variables are fine. $part_size = 20.0 (which *should* be a float, but it is a string), $first_number is $part_size + 20 which is 40.0 and that checks out. $second_number is $part_size - 20 which is 0.0 so that checks out as well.
    Your problem is elsewhere.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  14. #29
    New Coder
    Join Date
    Apr 2013
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hmmmmm, ok, the code I have is

    Code:
    $part_size = $row[size];
    $first_number = ($part_size + 20);
    $second_number = ($part_size - 20);
    var_dump($part_size, $first_number, $second_number);
    
    echo var_dump;
    
    
    $similar = mysql_query("SELECT * FROM products WHERE size >= $first_number AND size <= $second_number");
    
    while ($row = mysql_fetch_assoc($similar)) {
    	echo "
    		<tr class='right-cell'>
    			<td class='centered-cell'><img src = '".$row[image]."'/></td>
    			$row[part_num]</a></td>
    			<td>$row[size]</td>
    			<td>$row[depth]</td>
    		</tr>";
    }

  15. #30
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What's the datatype of size in your database?
    Edit:
    Actually, these are backwards. $first_number is 40 and $second_number is 0. You'll never find a size >= 40 and <= 0. Switch them around or use a BETWEEN syntax. $second_number has to be the lower bound.
    Last edited by Fou-Lu; 05-04-2013 at 04:53 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


 
Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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