hyper link using php

FratBro23
Category:
Programming
Price: $5 USD

Question description

I am trying to create a hyper link that will link to the id number of the sql item for every link.

example:
im trying to make the "id" in a sql query link with the same number as the id
so like id = 1
create a hyper link that would make it localhost/?page=1
id = 2
localhost/?page=2
and so on
but more complicated like a product number 4567-2443
so it would be localhost/?page=4567-2443

The goal is I will have 28,000 items in a table split by categories. when i click the product id i want to link to its page which will always be www.yourdomain.com/?product=<product id>

any suggestions help. This is the code I have so far to display the table and pagination.


<?php
 
 $link = mysql_connect( ':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root' ); mysql_select_db('products');
 
 if (!$link){
 echo "Could not connect to database" . mysql_error();
 exit();
 }
$db_name = "products";
 if (!mysql_select_db($db_name, $link)){
 die ("Could not select database" . mysql_error());
 }

  $per_page = 2;
  $pages_query = mysql_query("SELECT COUNT(`id`) FROM `beans`"); $pages = ceil (mysql_result($pages_query, 0) / $per_page);
  $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; $start = ($page - 1) * $per_page;
  $id = $query_row['id'];
  $query = mysql_query("SELECT * FROM `beans` LIMIT $start, $per_page");
 while ($query_row = mysql_fetch_assoc($query)) {
 echo '<p>', $query_row['id'] ,$query_row['name'] ,'</p>';
 
 }
 
 if ($pages >= 1) {
 for ($x = 1; $x <= $pages; $x++) {
 echo '<a href="?page=' . $x . '">' . $x . '</a> ';
 }
 
 }
  ?>

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: University of Maryland
PREMIUM TUTOR
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1830 tutors are online

Related Programming questions

05/14/2013
05/14/2013
05/13/2013
05/13/2013

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors