SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Please can somebody help me

    Hi all,

    Please can somebody help me out with passing data from one page to another via a url variable?
    It is driving me mad.

    I want to give the user a drop down which is dynamically filled with categories, a-z, on a page named choice.php. This i have managed to do.

    Then, i want the url to display their selection and send it to the next page...eg....www.gfsbersf.com/view.php?id=n.

    Then i want the page, (view.php), to display all records under the category of 'n' in the database.

    I can't get my head around how the variable gets passed, and received.

    If anybody could help me out it would be much appreciated.


    Many Thanks,
    Steve

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand what you are saying, all you need is some HTML to pass the variable, and some PHP to interpret it. I usually use a wysiwig editor for forms so this code might not all be right, but it should look something like this:

    HTML Code:
    <form action="view.php" method="GET"><select name="id">
    <option value="43">option1</option>
    <option value="59">option2</option>
    </select><input type="submit"></form>
    This would give you a url of something like this: /view.php?id=43.

    Then you get the ID in php, and you can do whatever you want with it:

    PHP Code:
    $request_id _GET["id"];
    //Now $requst_id has the number that was passed 
    I hope I answered the right question, good luck with it.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to give the user a drop down which is dynamically filled with categories, a-z, on a page named choice.php.
    That means choice.php has a form on it that contains your select element.

    I can't get my head around how the variable gets passed, and received.
    The name of the select along with the value attribute of the selected option is automatically sent to the page specified in the form's action attribute, e.g.
    Code:
    <form method="get" action="somepage.php">
    
    <select name="id">
    <option value="a123">choice 1</option>
    <option value="b678">choice 2</option>
    </select>
    
    <input type="submit" value="Submit" />
    </form>
    If the method attribute in the form tag is 'get', then on the page somepage.php the value of the id will be in the $_GET[] array, and you access it like this:

    echo $_GET['id'];

    If the method attribute of the form tag is 'post', then on the page somepage.php the value of the id will be in the $_POST array, and you access it like this:

    echo $_POST['id'];

  4. #4
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks u 2...will give it a go

    Steve

  5. #5

  6. #6
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to be a pain, but i cant get it to display anything.

    here is the code...

    <?php require_once('.htconfig.php'); ?>
    <?php
    $colname_Recordset1 = "-1";
    if (isset($_POST['$request_id'])) {
    $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['$request_id'] : addslashes($_POST['$request_id']);
    }
    mysql_select_db($database_soundflicksdb, $soundflicksdb);
    $query_Recordset1 = sprintf("SELECT artist_name, album_title, category FROM upload2 WHERE category = '%s' ORDER BY artist_name DESC", $colname_Recordset1);
    $Recordset1 = mysql_query($query_Recordset1, $soundflicksdb) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <p>
    <?php
    echo $_GET['id'];
    ?>
    <?php
    $request_id = _GET['id'];
    ?>

    </p>
    <table width="40%" border="1" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td><div align="center"><?php echo $row_Recordset1['artist_name']; ?></div></td>
    </tr>
    <tr>
    <td><div align="center"><?php echo $row_Recordset1['album_title']; ?></div></td>
    </tr>
    </table>
    <p align="center">&nbsp;</p>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>

    Can anyone help?

    Many Thanks once more,
    Steve

    Page above is view.php btw

  7. #7
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $request_id _GET['id']; 
    You missed out a $ sign before the _GET. Thats the first thing I noticed.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  8. #8
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that.
    I had to cut some out as i left the recordset query in from before when i was trying to do it myself.
    I have now ammended it, but it still will not show anything

    Code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled</title>
    </head>
    <?php require_once('.htconfig.php'); ?>
    <body>
    <?
    $request_id = $_GET["id"];


    while($my_data = mysql_fetch_array($request_id))
    {
    echo "<table align=center width=50% cellpadding=1 cellspacing=0 border=0>";
    echo "<tr>";
    echo "<td>";

    echo $my_data['artist_name'];
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo $my_data['album_title'];
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo $my_data['album_info'];
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo '<img src ="/images/'.$my_data['name'].'">';
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    }
    ?>
    </body>
    </html>

  9. #9
    SitePoint Zealot blackman890's Avatar
    Join Date
    Feb 2005
    Location
    Iceland
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is it just me, or have you completely missed some mysql code there?

    PHP Code:
    $request_id $_GET["id"];

    while(
    $my_data mysql_fetch_array($request_id)) 
    this would definately always return a null since $request_id is not a mysql array.
    Jonatan Nilsson
    Iceland
    C# Programmer - XML & DirectX (y = hx + c)

  10. #10
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, great thanks...It's alive now

    Many Thanks all

  11. #11
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could anybody tell me if there is a way of turning the displayed album titles into links to the appropiate page?

    Thanks again,
    Steve


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
  •