SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Database extraction by row

    Hello,

    I can't get this trought.

    My link will be:

    http://localhost/blabla/file.php?action=5

    If action = 5 then the 5 ROW from a table in the database will show.
    If action = 88 then the 88 ROW from a table will show.

    Got my point?

    I know how to show the info, I just don't know how to privatly show only ONE row. the action = number should be my ID witch is auto_increment.

    I also do that with SWITCH.

  2. #2
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    London
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The query should be something like:

    $sql= "select * from table_name where id=" . $_GET['action'];

    Not sure what you mean by "I just don't know how to privatly show only ONE row"... so post back if this isn't what you're looking for

  3. #3
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    	$query = "SELECT * FROM `problems` ORDER BY `prob_id`";
        $result = mysql_query($query);
      	$num_results = mysql_num_rows($result);
      	$row = mysql_fetch_array($result);
      	
      	if(!isset($_GET['actiune'])) $_GET['actiune'] = '';
      	$id = $row['prob_id'];
    switch ($_GET['actiune']){
    	case $id:
    ?>
    <table class="tabel_list" cellspacing="0">
      <tr>
        <td colspan="2" class="tabel_login_header">PROBLEM VIEW </td>
      </tr>
      <tr>
        <td><?= $row['prob_id'] ?></td>
        <td><?= $row['name'] ?></td>
      </tr>
      <tr>
        <td>ADRESA</td>
        <td><?= $row['address'] ?></td>
      </tr>
      <tr>
        <td>DESCRIERE</td>
        <td><?= $row['description'] ?></td>
    This is part of my code. The part bolded it's just something I tryed.
    So normaly I get the page showed, but ONLY with the first entry (the first row from the database). I want the "CASE" to be the ROW ID, si if page.php?actiune=5 I want the 5 row from the table to be showed.

  4. #4
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's wrong here:

    $query = "SELECT * FROM `problems` WHERE prob_id='. $_GET['actiune'] .' ORDER BY `prob_id`";

  5. #5
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    London
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because you're specifying the ID - and therefore returnng just one row - there's no need for the ORDER BY clause.

    Also, the single quotes in the GET are messing things up. Try this:

    $query = "SELECT * FROM `problems` WHERE prob_id=" . $_GET['actiune'];

  6. #6
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. i'v done it. Thanks.

  7. #7
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    London
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent!


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
  •