Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    I have a database I'm working on where I'm trying to accomplish a few different things...however one big goal is to have my search form return results based on a "%name%" wildcard, and have it provide a link which redirects to an output page that shows the data for that entire row.
    For instance, I search "Test" and am returned with three results from the "Name" column only. The goal is to be able to use the name as a link that will redirect to an output page that shows all the data from the row. I'm just clueless as to how to do it.
    Owner - http://www.project-guild.com (in development)

  2.  

  3. #2
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    To try to clarify a little with some code, here is my search query of my Database in a form style. What it outputs through the search is, using a while() command, searching the "Name" with wildcards.
    It works grand, however I'm only showing 3 out of 9 fields from that table, and I would like to link to a "viewitem.php" page that will act as a template to show the query in full. You can see my link in the search output as directing to "viewitem.php?id={$row['id']}" in an attempt to display the query.
    Code:
     
    <?php
    if(isset($_POST['search']))
    {
    include 'config.php';
    include 'dbopener.php';
     
    $stext = $_POST['stext'];
     
    $query = "SELECT * FROM eq2_idb WHERE name LIKE '%$stext%' LIMIT 0, 30";
    $result = mysql_query($query)or die('Error, insert query failed');
     
    {echo "<table border='1' cellpadding='0' cellpadding='2' width='100%'><tr><td align='center'>Name</td><td align='center'>Type</td><td align='center'>Level</td></tr>";}
     
    while($row = mysql_fetch_assoc($result))
     
    {echo "<tr><td><a href='viewitem.php?id={$row['id']}'>{$row['name']}</a></td><td>{$row['type']}</td><td>{$row['level']}</td></tr>";}
     
    {echo "<form method='post'><tr><td colspan='3' align='right'>Search Item Name:&nbsp;<input name='stext' type='text' id='stext'>&nbsp;<input name='search' type='submit' id='search' value='Search'></td></tr>";}
    {echo "</table>";}
     
    include 'dbcloser.php';
    }
    else
    {
    ?>
    <form method="post" onSubmit="return true">
    <table align="center" width="100%" border="1" cellspacing="0" cellpadding="2">
    <tr> 
    <td align="right">Search Item Name:&nbsp;<input name="stext" type="text" id="stext">&nbsp;<input name="search" type="submit" id="search" value="Search"></td>
    </tr>
    </table>
     
    </form>
    <?php
    }
    ?>
    Unfortunately, I'm at a loss at what I have to do to the "viewitem.php" page to allow it to actually post this. Would I have to use a $_GET method to retrieve the data through the URL string?
    Owner - http://www.project-guild.com (in development)

  4. #3
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    Further testing...this is what I've come up with to try and parse the URL String. When attempting this, using the "view.php?id=$id" link from the search page, it gives me an error stating to check my MySQL Syntax for an error at line 1 of the view.php file. Any ideas what I'm doing wrong here?
    Code:
     
    <?php 
    include 'config.php';
    include 'dbopener.php';
     
    $query = "SELECT * FROM eq2_idb WHERE id=$id"; 
    $result = mysql_query($query)or die(mysql_error()); 
    $row = mysql_fetch_assoc($result);
     
    {echo "{$row['name']}&nbsp;{$row['type']}&nbsp;{$row['tier']}&nbsp;{$row['skill']}&nbsp;{$row['wield']}&nbsp;{$row['level']}&nbsp;{$row['stat']}&nbsp;{$row['class']}&nbsp;{$row['slot']}";} 
     
    include 'dbcloser.php'; 
    ?>
    Owner - http://www.project-guild.com (in development)

  5. #4
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    Well, nevermind...I just happened to figure it out myself (kinda surprised myself). As an explaination, I merely forgot to use the $_GET option to define what $id was in my query string. After fixing that, it worked like a charm!
    Owner - http://www.project-guild.com (in development)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:16 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com