Lassie Posted October 28, 2008 Share Posted October 28, 2008 I have a page which displays books in a selected category.The selected category is passed in the url. When a thumbnail is selected a larger image and book deatils are shown I want to display a limited no of books and use a prev and next link to allow all to be shown. To do this the page use SERVER_SELF. I have 2 problems. 1. When I select a thumbnail for the full details to be shown I loose the cat id as it is passed in the Get method. 2. I have tried adding the cat id to the prev and next links but this produces a parse error. I think I will also have to amend the thumbnail link. Is what I am trying to do possible and how do I correct the syntax. The parse error lines are below followed by the script. echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='.($row['cat_id']).">< Prev</a>'; [code] echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).">Next ></a>'; [code] <?php include ('book_sc_fns.php'); // The shopping cart needs sessions, so start one session_start(); do_html_header(); $cat_id = $_GET['cat_id']; $name = get_category_name($cat_id); //define number of cols in the table define('COLS',2); //set maxium number of records per page define('SHOWMAX',9); //connect to db $connection = db_connect(); // $cat_id=12; //prepare sql to get total records $getTotal = "SELECT COUNT(*) as cnt FROM products WHERE cat_id='$cat_id'"; //sunbit query and store results as $totalPix $total = mysql_query($getTotal) or die("Problem with the query: $getTotal<br>" . mysql_error()); $row = mysql_fetch_assoc($total); $totalPix = $row['cnt']; //set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; // calculate the start row of the subset $startRow = $curPage * SHOWMAX; $query = "SELECT * from products WHERE cat_id='$cat_id'LIMIT $startRow, ".SHOWMAX; $result = mysql_query($query)or die("Problem with the query: $query<br>" . mysql_error()); if (!$result) return false; $num_cats = mysql_num_rows($result); if ($num_cats ==0) return false; $row = mysql_fetch_assoc($result); // get the name and caption for the main image $mainImage = $row['pix']; // get the name for the main image if(isset($_GET['image'])) { $mainImage = $_GET['image']; } else{ $mainImage = $row['pix']; } // get the dimensions of the main image $imageSize = getimagesize('images/'.$mainImage); ?> <h1 class="align-center"><?php echo $name;?></h1> <p id="picCount">Displaying <?php echo $startRow+1; if ($startRow+1 < $totalPix) { echo ' to '; if ($startRow+SHOWMAX < $totalPix) { echo $startRow+SHOWMAX; } else { echo $totalPix; } } echo " of $totalPix"; ?></p> <div class="float-divider"></div> <div id="gallery"> <table id="thumbs"> <tr> <!--This row needs to be repeated--> <?php //initialised cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['pix'] == $mainImage) { $caption = $row['title']; $about=$row['product_desc']; } ?> <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['pix']; ?>&curPage=<?php echo $curPage; ?>"><img src="images/<?php echo $row['pix']; ?>" alt="<?php echo $row['title']; ?>" width="80" height="54" /></a> </td> <td class="thumbs"><?php echo $row['title'];?></td> <?php $row = mysql_fetch_assoc($result); //increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> <!-- Navigation link needs to go here --> <td><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='.($row['cat_id']).">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).">Next ></a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> <div id="right"> <table width="350" align="center"> <tr> <td colspan="2" align="center"><?php echo $caption; ?></td> </tr> <tr> <td> <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p> </td> <td><?php echo $about;?></td> </tr></table> </div> </div><!--End Div Gallery--> <?php do_html_footer(); exit(); ?> [/code] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/ Share on other sites More sharing options...
GKWelding Posted October 28, 2008 Share Posted October 28, 2008 for a start, replace line 131 to 151 with the following... if ($curPage > 0) { echo "<a href=\"'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='.($row['cat_id']).\">< Prev</a>"; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo "<a href=\"'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).\">Next ></a>"; Your echo quoting was screwed up, try that and then see what happens, I haven't reviewed all of the code yet but that was the obvious stuff. EDIT: Making code more readable... Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676620 Share on other sites More sharing options...
Lassie Posted October 28, 2008 Author Share Posted October 28, 2008 Thanks. I get pass error T_String etc on 139. Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676622 Share on other sites More sharing options...
GKWelding Posted October 28, 2008 Share Posted October 28, 2008 Can you post the full code so I have a chance of finding line 139? Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676624 Share on other sites More sharing options...
Lassie Posted October 28, 2008 Author Share Posted October 28, 2008 Hi, Full code below and thank you for your interest. I have in this version error on 152. Now 152 is the same code almost as 131 which doesnt give an error. <?php include ('book_sc_fns.php'); // The shopping cart needs sessions, so start one session_start(); do_html_header(); $cat_id = $_GET['cat_id']; $name = get_category_name($cat_id); //define number of cols in the table define('COLS',2); //set maxium number of records per page define('SHOWMAX',9); //connect to db $connection = db_connect(); // $cat_id=12; //prepare sql to get total records $getTotal = "SELECT COUNT(*) as cnt FROM products WHERE cat_id='$cat_id'"; //sunbit query and store results as $totalPix $total = mysql_query($getTotal) or die("Problem with the query: $getTotal<br>" . mysql_error()); $row = mysql_fetch_assoc($total); $totalPix = $row['cnt']; //set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; // calculate the start row of the subset $startRow = $curPage * SHOWMAX; $query = "SELECT * from products WHERE cat_id='$cat_id'LIMIT $startRow, ".SHOWMAX; $result = mysql_query($query)or die("Problem with the query: $query<br>" . mysql_error()); if (!$result) return false; $num_cats = mysql_num_rows($result); if ($num_cats ==0) return false; $row = mysql_fetch_assoc($result); // get the name and caption for the main image $mainImage = $row['pix']; // get the name for the main image if(isset($_GET['image'])) { $mainImage = $_GET['image']; } else{ $mainImage = $row['pix']; } // get the dimensions of the main image $imageSize = getimagesize('images/'.$mainImage); ?> <h1 class="align-center"><?php echo $name;?></h1> <p id="picCount">Displaying <?php echo $startRow+1; if ($startRow+1 < $totalPix) { echo ' to '; if ($startRow+SHOWMAX < $totalPix) { echo $startRow+SHOWMAX; } else { echo $totalPix; } } echo " of $totalPix"; ?></p> <div class="float-divider"></div> <div id="gallery"> <table id="thumbs"> <tr> <!--This row needs to be repeated--> <?php //initialised cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['pix'] == $mainImage) { $caption = $row['title']; $about=$row['product_desc']; } ?> <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['pix']; ?>&curPage=<?php echo $curPage; ?>"><img src="images/<?php echo $row['pix']; ?>" alt="<?php echo $row['title']; ?>" width="80" height="54" /></a> </td> <td class="thumbs"><?php echo $row['title'];?></td> <?php $row = mysql_fetch_assoc($result); //increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> <!-- Navigation link needs to go here --> <td><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='.($row['cat_id']).">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).">> Next</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> <div id="right"> <table width="350" align="center"> <tr> <td colspan="2" align="center"><?php echo $caption; ?></td> </tr> <tr> <td> <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p> </td> <td><?php echo $about;?></td> </tr></table> </div> </div><!--End Div Gallery--> <?php do_html_footer(); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676647 Share on other sites More sharing options...
GKWelding Posted October 28, 2008 Share Posted October 28, 2008 ok, replace all of that code you just gave with this and see if that works... <?php include ('book_sc_fns.php'); // The shopping cart needs sessions, so start one session_start(); do_html_header(); $cat_id = $_GET['cat_id']; $name = get_category_name($cat_id); //define number of cols in the table define('COLS',2); //set maxium number of records per page define('SHOWMAX',9); //connect to db $connection = db_connect(); // $cat_id=12; //prepare sql to get total records $getTotal = "SELECT COUNT(*) as cnt FROM products WHERE cat_id='$cat_id'"; //sunbit query and store results as $totalPix $total = mysql_query($getTotal) or die("Problem with the query: $getTotal<br>" . mysql_error()); $row = mysql_fetch_assoc($total); $totalPix = $row['cnt']; //set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; // calculate the start row of the subset $startRow = $curPage * SHOWMAX; $query = "SELECT * from products WHERE cat_id='$cat_id'LIMIT $startRow, ".SHOWMAX; $result = mysql_query($query)or die("Problem with the query: $query<br>" . mysql_error()); if (!$result) return false; $num_cats = mysql_num_rows($result); if ($num_cats ==0) return false; $row = mysql_fetch_assoc($result); // get the name and caption for the main image $mainImage = $row['pix']; // get the name for the main image if(isset($_GET['image'])) { $mainImage = $_GET['image']; } else{ $mainImage = $row['pix']; } // get the dimensions of the main image $imageSize = getimagesize('images/'.$mainImage); ?> <h1 class="align-center"><?php echo $name;?></h1> <p id="picCount">Displaying <?php echo $startRow+1; if ($startRow+1 < $totalPix) { echo ' to '; if ($startRow+SHOWMAX < $totalPix) { echo $startRow+SHOWMAX; } else { echo $totalPix; } } echo " of $totalPix"; ?></p> <div class="float-divider"></div> <div id="gallery"> <table id="thumbs"> <tr> <!--This row needs to be repeated--> <?php //initialised cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['pix'] == $mainImage) { $caption = $row['title']; $about=$row['product_desc']; } ?> <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['pix']; ?>&curPage=<?php echo $curPage; ?>"><img src="images/<?php echo $row['pix']; ?>" alt="<?php echo $row['title']; ?>" width="80" height="54" /></a> </td> <td class="thumbs"><?php echo $row['title'];?></td> <?php $row = mysql_fetch_assoc($result); //increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> <!-- Navigation link needs to go here --> <td><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo "<a href=\"'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='.($row['cat_id']).\">< Prev</a>"; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo "<a href=\"'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).\">Next ></a>"; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> <div id="right"> <table width="350" align="center"> <tr> <td colspan="2" align="center"><?php echo $caption; ?></td> </tr> <tr> <td> <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p> </td> <td><?php echo $about;?></td> </tr></table> </div> </div><!--End Div Gallery--> <?php do_html_footer(); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676654 Share on other sites More sharing options...
Lassie Posted October 28, 2008 Author Share Posted October 28, 2008 Gives me syntax error on 132 What did you change? Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676707 Share on other sites More sharing options...
GKWelding Posted October 28, 2008 Share Posted October 28, 2008 what does the error say exactly? Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676712 Share on other sites More sharing options...
Lassie Posted October 28, 2008 Author Share Posted October 28, 2008 Unexpected T_Encapsed and Whitespace Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676725 Share on other sites More sharing options...
sasa Posted October 28, 2008 Share Posted October 28, 2008 change lines echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).">> Next</a>'; to echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).'>> Next</a>'; change last " to ' in lines 132 and 153 Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676848 Share on other sites More sharing options...
Lee-Bartlett Posted October 28, 2008 Share Posted October 28, 2008 NVM Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-676856 Share on other sites More sharing options...
Lassie Posted October 29, 2008 Author Share Posted October 29, 2008 Thanks all. However I still have same parse error on 155. Should the first " be matched at the end? echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).'>> Next</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-677266 Share on other sites More sharing options...
Lassie Posted October 29, 2008 Author Share Posted October 29, 2008 I now have a parse free script but my cat_id is not adding to the url. I have verified that the $row['cat_id'] holds the category. Can anyone help please. <?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='. ($row['cat_id']).'">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 3 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).'">Next ></a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> Full script <?php include ('book_sc_fns.php'); // The shopping cart needs sessions, so start one session_start(); do_html_header(); $cat_id=$_GET['cat_id']; $name = get_category_name($cat_id); //define number of cols in the table define('COLS',2); //set maxium number of records per page define('SHOWMAX',9); //connect to db $connection = db_connect(); //prepare sql to get total records $getTotal = "SELECT COUNT(*) as cnt FROM products WHERE cat_id='$cat_id'"; //sunbit query and store results as $totalPix $total = mysql_query($getTotal)or die ("Problem with the query: $getTotal<br>" . mysql_error()); $row = mysql_fetch_assoc($total); $totalPix = $row['cnt']; //set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; // calculate the start row of the subset $startRow = $curPage * SHOWMAX; $query = "SELECT * from products WHERE cat_id='$cat_id' LIMIT $startRow, ".SHOWMAX; $result = mysql_query($query)or die("Problem with query: $query<br>" . mysql_error()); if (!$result) return false; $num_cats = mysql_num_rows($result); if ($num_cats ==0) return false; $row = mysql_fetch_assoc($result); // get the name and caption for the main image $mainImage = $row['pix']; // get the name for the main image if(isset($_GET['image'])) { $mainImage = $_GET['image']; } else{ $mainImage = $row['pix']; } // get the dimensions of the main image $imageSize = getimagesize('images/'.$mainImage); ?> <h1 class="align-center"><?php echo $name;?></h1> <p id="picCount">Displaying <?php echo $startRow+1; if ($startRow+1 < $totalPix) { echo ' to '; if ($startRow+SHOWMAX < $totalPix) { echo $startRow+SHOWMAX; } else { echo $totalPix; } } echo " of $totalPix"; ?></p> <div class="float-divider"></div> <div id="gallery"> <table id="thumbs" align="center"> <tr> <!--This row needs to be repeated--> <?php //initialised cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['pix'] == $mainImage) { $caption = $row['title']; $about=$row['product_desc']; } ?> <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['pix']; ?>&curPage=<?php echo $curPage; ?>"><img src="images/<?php echo $row['pix']; ?>" alt="<?php echo $row['title']; ?>" width="80" height="54" /></a></td> <td class="thumbs"><?php echo $row['title'];?></td> <?php $row = mysql_fetch_assoc($result); //increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> <!-- Navigation link needs to go here --> <td><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&cat_id='. ($row['cat_id']).'">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 3 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).'">Next ></a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> <div id="main_image"> <table align="center"> <tr> <td colspan="2" align="center"><?php echo $caption; ?></td> </tr> <tr> <td> <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p> </td> <td><?php echo $about;?></td> </tr></table> </div> </div><!--End Div Gallery--> <?php do_html_footer(); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-677381 Share on other sites More sharing options...
sasa Posted October 29, 2008 Share Posted October 29, 2008 you have extra space after & change echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'& cat_id='.($row['cat_id']).'">Next ></a>'; to echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'&cat_id='.($row['cat_id']).'">Next ></a>'; Quote Link to comment https://forums.phpfreaks.com/topic/130429-adding-value-to-url-string/#findComment-677397 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.