0

I have made dynamic links in PHP, to display individual bikes, using the bike ID in my website. This is my code that makes each link individual on my index page:

$bike_id = $bike["bike_id"];
      echo '<a href="./item.php?id='.$bike_id.'"><input type="button" value="See More" />';

Now the issue I face is trying to display each bike item pages unique values. for example, if you selected "Fast bike" on index.php, you'd be taken to a page that had "fast bikes" description and price.

In the database, I have the columns:

"Bike_name", "Bike_Price", "Bike_Description

and on each the bikes item page, I want to display these values, but I don't know how to do it.

Here is what I have so far but it's not working:

<?php

require_once(__DIR__.'/includes/db.php'); //connect to the database

$item_id = $_GET['id']; //get the ID of the item

$item_data = mysql_query("SELECT bike_name"); //get the value of the column bike_name

echo "<h2>".$item_data['bike_name']."</h2>"; //display the value of the column bike_name
?>

I was advsed to do this:

// Select item from database
// Store results in $item_data
// echo $item_data[`item_name`];

My connection (I'm not showing my passwords or usernmane)

try {
  $Conn = new PDO("mysql:host=".$db_config['db_host'].";dbname=".$db_config['db_name'],$db_config['db_user'],$db_config['db_pass']);
  $Conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  $Conn->setAttribute(PDO::ATTR_PERSISTENT, true);
  $Conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (PDOException $e) {
  echo $e->getMessage();
  exit();
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Marvin
  • 65
  • 1
  • 8
  • Your SQL statement looks incomplete. – JollyRoger Dec 10 '20 at 16:22
  • 1
    @JollyRoger That is pseudo-code, it's what they are asking how to do. – Dharman Dec 10 '20 at 16:23
  • 1
    Ok, first of all **DO NOT USE** `PDO::ATTR_PERSISTENT`. This is a very niche feature that will definitely be a source of a lot of problems for you. Just remove that line. – Dharman Dec 10 '20 at 16:26
  • That really didn't answer my question, why was this closed? – Marvin Dec 10 '20 at 16:35
  • @Marvin: there are now two duplicate questions where the answers show to execute a select sql statement via PDO and then display the results. As far as I'm concerned, that's what your question was about. – Shadow Dec 10 '20 at 17:00
  • Your first code block contains `mysql_query`, which [has been removed from PHP](https://stackoverflow.com/questions/12859942/). The second one uses PDO, but it's not clear at all how any of these relate to one another. – Machavity Dec 10 '20 at 17:07

0 Answers0