2

What you are seeing is my code that displays images as a search result. I have an anchor down there so when you click on the picture it sends you to a TEST page.

I want to have a page set up that will display the rest of the row entries that are associated with that picture:

(Picture)    Player: Steve Sax
             Card Type: Donruss
             Year: 1989
             Value: $2.00

How do I grab the "id" in the row of the search result and then echo it in a table that shows up on the TEST page?

<?php
$servername = "*********";
$username = "*********";
$password = "*********";
$dbname = "*********";
$username1=$_SESSION['activeusername'];
    $userid = $_SESSION['activeid'];
    $userid = $_SESSION['activeid'];
    $itemid = $_SESSION['activeid'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT * FROM useritems JOIN (users, iteminfo) on (users.id=useritems.UserID AND iteminfo.ID=useritems.ItemID) AND userid='2'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "<a href='test1.php'><div id='frame'>
<div id='splash-image' style='background: url(".$row['imagename']."); background-size:cover;'></div>
<div id='text'>
<table >
<tr></tr>
</table>
</div>
</div>";
    }
} else {
    echo "You Have No Items In Your Closet!!!";
}

mysqli_close($conn);
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    I'm not really following what you are trying to do. How do you determine if something is "associated"? And the ID should be in `$row['id']` (or whatever you called your ID column). – Mike Aug 26 '15 at 19:33

2 Answers2

0

Assuming the id you want is the item's id, you would echo out

$row['ItemID']

If you wanted to include this ID into your href as a GET parameter you could do something like:

echo "<a href='test1.php?ItemID=" . $row['ItemID'] ."'>...</a>";

Then, in your test1.php, you can retrieve the Item ID for use in your query (after sanitizing it!) by accessing the $_GET global.

$ItemID = $_GET['ItemID'];

If you just wanted the result set row number (not tied to user id or item id), you could echo out something like: $counter++

or take a look at MySQL - Get row number on select

Community
  • 1
  • 1
Pete
  • 1,305
  • 1
  • 12
  • 36
  • Hi Pete, thanks for responding. The way it works right now is a search result comes back with a bunch of baseball cards...If they click on a card based on the picture I want to be able to pull the rest of the information on to another page. Right now the way I am set up is that the click on an image they want to know more about and it just forwards them to a page. What I can't wrap my mind around is how to grab the itemid from the picture they clicked...and use it in an echo on the page they are going too... – This site sucks Aug 26 '15 at 19:49
  • Hi Pete, just a follow up question...You don't have to tell me how to do it, but is it possible to use the ID that came over to display the rest of the information in the row...something like echoing the entire row based on the id? – This site sucks Aug 26 '15 at 22:23
0

Pass the id with get as:

echo "<a href='test1.php?id=". $row['id']."'>

And get it on the landing page as:

$id=$_GET['id'];
echo $id;
Rahul Kumar
  • 99
  • 3
  • 10