SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member white_spider77's Avatar
    Join Date
    Feb 2003
    Location
    wales
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Slightly stuck using GET, need fresh eyes

    Hi, I'm trying to pass two variables via a url link and then to take the last variable to gather info from a mysql db.

    MYSQL table name are hDetails which holds the id, name records and RATES table which holds the tid.

    I want display all tid from RATES which is specific to the id from hDetails.

    FRONTPAGE LINK :
    (mysql table : hDetails)
    $id
    $name

    (mysql table : RATES)
    $tid
    this is my link from the frontpage which collects the variables successfully and passes it to the details.php

    <STRONG><a href="details.php?id=$id&tid=$tid></STRONG></FONT></DIV><DIV><STRONG><FONT color=#ff0000></FONT></STRONG> </DIV><DIV><FONT color=black>The result I get in the url goes like : details.php?id=1&7</FONT></DIV><DIV> </DIV><DIV>DETAILS.PHP /DIV><DIV> </DIV><DIV><FONT color=red>$result = mysql_query("SELECT id, name FROM hdetails WHERE id=" . $_GET["id"]);
    the above will take the variable i passed from url and display the info for that id only. This works but the next bit :

    $rack = mysql_query("SELECT tid FROM rates WHERE tid=" . $_GET["tid"]);

    I can't seem to get the tid variable from the same url. Is what i'm doing correct or do I need to seperate them before calling them into the mysql query.

    I then need to show this as follows.
    <?php
    while($details = mysql_fetch_array=($result)){
    $id = $details["id"];
    $name = $details["name"];

    echo("<p>$id,$name</p>");
    }
    ?>

    and another section of the page to display the rates for that specific name as follows:

    <?php
    while($rates = mysql_fetch_array=($rack)){
    $tid = $details["tid"];

    echo("<p>$tid</p>");
    }
    ?>


    Each time I load the details.php page it loads the id and name successfully but throws an error for the tid.

    Can anyone take a look and see where I'm going wrong.
    white_spider77

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    You're trying to get the 'tid' out of the array details while it's in the array result.
    You also have a = in the while loop that shouldn't be there.
    Try:
    PHP Code:
    while($details mysql_fetch_array($result)) {
        
    $id $details["id"];
        
    $name $details["name"];
        echo 
    "<p>$id$name</p>";
    }
    // AND
    while($rates mysql_fetch_array($rack)) {
        
    $tid $rates["tid"];
        echo 
    "<p>$tid</p>";

    Hope this helps

    -Helge

  3. #3
    SitePoint Member white_spider77's Avatar
    Join Date
    Feb 2003
    Location
    wales
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Helge,

    Am I right in thinking I can get two variables from the url. Only it seems that however I try retrieving the variables from the url it only gives the ['id'] and not the ['tid'].

    I will try again later. If not I think I have thought of another way, that is give both tables a [name] column and pass that variable instead through the url. The [name] is unique and cannot be duplicated, therefore I assume I can pull all the rates for the one name.

    I'll try it......
    Anyway thanks again for all your help Helge.

    white_spider77

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by white_spider77
    Am I right in thinking I can get two variables from the url.
    Yes.
    Only it seems that however I try retrieving the variables from the url it only gives the ['id'] and not the ['tid'].
    Try to echo out the variables from the url and the queries. Also add some errorchecking to the mysql_query()
    PHP Code:
     
    $sqlDetails
    ="SELECT id, name FROM hdetails WHERE id=" $_GET['id'];
    echo 
    "sqlDetails: $sqlDetails";
    $result mysql_query($sqlDetails) or die(mysql_error());

    while(
    $details mysql_fetch_array($result)) {
        
    $id $details["id"];
        
    $name $details["name"];
        echo 
    "<p>$id,$name</p>";
    }


    $sqlRates "SELECT tid FROM rates WHERE tid=" $_GET['tid'];
    echo 
    "sqlRates: $sqlRates";
    $rack mysql_query($sqlRates) or die(mysql_error());
     
    while(
    $rates mysql_fetch_array=($rack)){
        
    $tid $rates["tid"];
        echo 
    "<p>$tid</p>";

    -Helge

  5. #5
    SitePoint Member white_spider77's Avatar
    Join Date
    Feb 2003
    Location
    wales
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would you also happen to know how I would get javascriptpen_window function to launch a window with a picture but reference to the php?id. or where I can find the script that will do the following.

    The site I'm working on you see is a hotel booking website. Therefore the front page will hold the hotels, a user clicks on the hotel, this will then take you to the hotels details page. On this page are three thumbnails (which i can successfully load from the ['id']). However I want to user to be able to click to image and launch a pop up window with the enlarged image. I can do this with javascript but how do I get the function to hold the php ['id'] to load the correct images with reference to the hotel details.

    cheers
    white_spider77

  6. #6
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm don't know much about JS though , but this might work.
    Code:
    // thumbnails page
    <img src="#" onclick="window.open("viewpic.php?picid=$pictureid")" />
     
     
    // ------------
    // viewpic.php
     
    $picid = $_GET['picid'];
    // Then the rest of the diplay picture code
    About the JS. You should try to find more about how to do with people that have disabled JS in their browser. How would you deal with them? I'm sorry I can't help you more with that issue.

    BTW, how did you other question sort out?

    -Helge

  7. #7
    SitePoint Member white_spider77's Avatar
    Join Date
    Feb 2003
    Location
    wales
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've managed to echo the variables successfully. It seems to be my query is the problem. I'm looking into this. I'm not really happy with the db structure anyway so there might be a radical change. (Im admit that I did rush into the structure due to time constraints). However all you help is much appreciated.

    I'm confident that once my query is sorted I'll be rolling. It's only cosmetic stuff really.

    white_spider77
    p.s. I'll send you the results once finished.

  8. #8
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, glad you got it sorted out.

    If you need further assistant on the JS problem, you might want to ask in JavaScript forum.

    -Helge


Bookmarks

Posting Permissions

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