PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
soianyc
Forum Commoner
Posts: 61 Joined: Wed Mar 30, 2005 2:48 pm
Location: NY
Post
by soianyc » Thu Apr 14, 2005 10:08 pm
Im trying to make a dynamic link from something i grabbed from a databse. The database shows an image and when i click on that image i want a link that gets created on a new tempelate with more pics included.
Here is the code i have written so far
Code: Select all
<body>
<br>
<br>
<?php
// Database Connection
include 'connect.php';
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 6;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM coats LIMIT $from, $max_results");
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM coats"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
//echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$prevs .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<[Previous]</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//echo "$i ";
} else {
$pages .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\"> $i </a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$nexts .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">[Next]>></a>";
}
//echo "</center>";
?>
<table class="mainTable" align="center">
<td align="left" valign="top" width="100">
<?coatmenu();?>
</td>
<td align="center" valign="top" width="600">
<table class="topmiddle" >
<td class ="topcenterpic" colspan=2 align="center" width=350>Online Catalog<br><a class="pic" href="mensmain.php"><img src="pix/men.jpg"></a><img src="pix/dash.jpg"><img src="pix/women.jpg"><br><?//=$prevs?><?//=$pages?><?//=$nexts?></td><td width=250>Search: <INPUT maxLength=200 size=18></td>
<tr>
<?php
$k=0;
while($row = mysql_fetch_array($sql)){
$l = 3;
if (($k % $l) == 0){
echo '<tr></tr>';
}
echo '<td class="maindisplay"><img src="pix/'.$row["name"].'"><br>'.$row["shortdescript"].'<br>'.$row["price"].'</td>';
$k++;
}
?>
</table>
</td>
</table>
</body>
Here is where i grab the data. i wanna make a link to a tempelate i have named mainitem.php
How do i proceed
Regards
Chris
feyd | Please review how to post code using Code: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by
soianyc on Fri Apr 15, 2005 11:11 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Apr 14, 2005 10:58 pm
so..... make a link to the script.. what's the problem?
soianyc
Forum Commoner
Posts: 61 Joined: Wed Mar 30, 2005 2:48 pm
Location: NY
Post
by soianyc » Fri Apr 15, 2005 8:42 am
Where im getting confused is, How does the link get the info for the page. For example. They click on a garment, which goes to a page that shows a detail description of that item. If i just make a link to it how does it know where to take the data from???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 15, 2005 8:46 am
you pass information in the URL they are sent to.. something such as a record id to use for fetching the information from the database for display.
soianyc
Forum Commoner
Posts: 61 Joined: Wed Mar 30, 2005 2:48 pm
Location: NY
Post
by soianyc » Fri Apr 15, 2005 9:51 am
So from what your saying, you create a link in the script, and you pass the row number into the new page????
soianyc
Forum Commoner
Posts: 61 Joined: Wed Mar 30, 2005 2:48 pm
Location: NY
Post
by soianyc » Fri Apr 15, 2005 11:13 am
How do i setup a link to pass those records though??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 15, 2005 11:19 am
you're already basically doing it in your while loop.. you just need to add the html code parts and the proper query string on the url..
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri Apr 15, 2005 11:20 am
if you look in the address bar while using this forum you see somethining like
viewtopic.php?t=32574&highlight=
and then when you click on the reply button you see something like
posting.php?mode=reply&t=32574
so in your <a href you migh have something like
Code: Select all
<a href="e;www.yoursite.com/detial.php?garmentId=23><img src="e;pic_23.gif"e; /></a>
then on your detail page you would get the garmentId and do a db search to get the right data and display it.
phpScott
soianyc
Forum Commoner
Posts: 61 Joined: Wed Mar 30, 2005 2:48 pm
Location: NY
Post
by soianyc » Fri Apr 15, 2005 1:48 pm
Ok, here is what i got, but it still isnt working.
Code: Select all
$k=0;
while($row = mysql_fetch_array($sql)){
$l = 3;
if (($k % $l) == 0){
echo '<tr></tr>';
}
$item_id = $row["id"];
echo '<td class="maindisplay"><a href="mainitems.php?$item_id"><img src="pix/'.$row["name"].'"></a><br>'.$row["shortdescript"].'<br>'.$row["price"].'</td>';
$k++;
}
the link is not working, and i cant understand why. I think im on the right path .
soianyc
Forum Commoner
Posts: 61 Joined: Wed Mar 30, 2005 2:48 pm
Location: NY
Post
by soianyc » Fri Apr 15, 2005 2:51 pm
Ok i got the rest of it to work.
Thanx to everyone for the help
-soianyc