affordit Posted February 5, 2008 Share Posted February 5, 2008 The code below is not carrying thru the variable $prod from the switch below. Can anyone please show me how to fix this?? <?php echo( '<strong>Page:</strong> ' ); if ( $start > 1 ) echo ' ... '; for ( $i = $start; $i <= $end; $i++ ) { if ( $i == $curentPage ) echo( '<span style="font-weight:bold;">' . $i . '</span>' ); else echo ' <a href="?id=' . $_GET['id'] . '&page=' . $i . '" style="font-size:1.00em;">' . $i . '</a> '; } if ( $end < $totalPages ) echo ' ... '; echo( "<strong> of {$totalPages}</strong>" ); ?> </td> <?php if ($page == $lastPage) { ?> <td width="15%" style="padding:0;"> Next | Last </td> <?php } else { $nextPage = $page + 1; ?> <td width="15%" style="padding:0;"> <a href="?page=<?php echo( $nextPage ); ?>">Next</a> | <a href="?page=<?php echo( $lastPage ); ?>">Last</a> </td> <?php } print "<table align='center' border='1'><tr><td>"; switch ($prod) { default: print "<table align'center'><tr><td align='center'> Please choose what products you'd like to look at:</td></tr>"; echo "<tr><td align='center'> <A HREF=random_product5.php?prod=toys>Toys</A> <A HREF=random_product5.php?prod=batteries>Batteries</A> <A HREF=random_product5.php?prod=auto>Automotive</A> <A HREF=random_product5.php?prod=apparal>Apparal</A> <A HREF=random_product5.php?prod=housewares>Housewares</A> <A HREF=random_product5.php?prod=tools>Tools</A> <A HREF=random_product5.php?prod=hardware>Hardware</A> <A HREF=random_product5.php?prod=electronics>Electronics</A> </td></tr></table>"; } print "</td></tr></table>"; ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 I don't see where you set $prod before the switch Quote Link to comment Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 You haven't set $prod anywhere. So there is nothing to carry through. Not that it should matter - you have no cases for your switch statement, so its going to do the default statement regardless of whether $prod is set or not. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 I hope there is some code above that, because your table layout is all wacked out. Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 There is code above that but I was trying not to put to much here I will post it all if needed but I figure this is where the problem is as an example when I click on the Toys link in the switch this is what it the end of the link looks like random_product5.php?prod=toys This is what I get accross the bottom of the page: First | Previous Page: 1 2 of 2 Next | Last When I hover over the 2 this is what the end of the link looks like. random_product5.php?id=&page=2 And I dont get the second set of five produt when I activate the link. When I manually enter this: random_product5.php?prod=toys&id=&page=2 I can get to the next group of products. Here is the intire page <?php session_start(); include"client_info3.php"; print "<table align='center' border='1'><tr><td>"; switch ($prod) { default: print "<table align'center'><tr><td align='center'> Please choose what products you'd like to look at:</td></tr>"; echo "<tr><td align='center'> <A HREF=random_product5.php?prod=toys>Toys</A> <A HREF=random_product5.php?prod=batteries>Batteries</A> <A HREF=random_product5.php?prod=auto>Automotive</A> <A HREF=random_product5.php?prod=apparal>Apparal</A> <A HREF=random_product5.php?prod=housewares>Housewares</A> <A HREF=random_product5.php?prod=tools>Tools</A> <A HREF=random_product5.php?prod=hardware>Hardware</A> <A HREF=random_product5.php?prod=electronics>Electronics</A> </td></tr></table>"; } print "</td></tr></table>"; include("sharons_dbinfo.inc.php"); mysql_connect(mysql,$name,$password); mysql_select_db(mydatabase) or die( "Unable to select database"); //Count rows $query = "SELECT count(*) FROM content WHERE category = '$prod'"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $page = ( isset( $_GET['page'] ) && is_numeric( $_GET['page'] ) ) ? $_GET['page'] : 1; $query = "SELECT count(*) FROM content WHERE category = '$prod'"; $result = mysql_query( $query ); $fetch = mysql_fetch_row( $result ); $numRows = $fetch[0]; $rowsPerPage = ( isset( $_GET['show'] ) && is_numeric( $_GET['show'] && $_GET['show'] >= 1 ) && $_GET['show'] <= 40 ) ? $_GET['show'] : 5; $lastPage = ceil( $numRows / $rowsPerPage ); $page = (int)$page; if( $page < 1 ) { $page = 1; } elseif( $page > $lastPage ) { $page = $lastPage; } if( $numRows > 0 ) $limit = 'LIMIT ' . ( $page - 1 ) * $rowsPerPage . ',' . $rowsPerPage; else $limit = ''; //Query the DB $query = "SELECT * FROM content WHERE category = '$prod' $limit"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); // PROCESS CONTENTS OF $RESULTS print "<table width='700' align='center'><tr>"; while ($info = mysql_fetch_array($result)) { print "<td width='0' ALIGN='CENTER'>"; echo $info['heading']; echo "<BR>"; echo $info['picture']; echo "<BR>"; echo $info['description']; echo"<BR></td>"; if($info['item'] == 5){ echo"</tr>"; } if($info['item'] == 10){ echo"</tr>"; } if($info['item'] == 15){ echo"</tr>"; } if($info['item'] == 20){ echo"</tr></table>"; } } $lastPage = (int)$lastPage; ?> <table width="100%" cellspacing="0"> <tr> <?php if ( $page == 1 ) { ?> <td width="15%" style="padding:0;"> <a href="#">First</a> | <a href="#">Previous</a> </td> <?php } else { $prevPage = $page - 1; ?> <td width="15%" style="padding:0;"> <a href="?page=1">First</a> | <a href="?page=<?php echo( $prevPage ); ?>">Previous</a> </td> <?php } $totalPages = $lastPage; $curentPage = $page; if ( $totalPages < 8 ) { $start = 1; $end = $totalPages; } else { if ( $curentPage > 3 ) { if ( $totalPages - $curentPage < 3 ) $end = $totalPages; else $end = $curentPage + 3; $start = $end - 6; } else { $start = 1; $end = 7; } } ?> <td width="70%" class="black_td" style="padding:0;text-align:center;"> <?php echo( '<strong>Page:</strong> ' ); if ( $start > 1 ) echo ' ... '; for ( $i = $start; $i <= $end; $i++ ) { if ( $i == $curentPage ) echo( '<span style="font-weight:bold;">' . $i . '</span>' ); else echo ' <a href="?id=' . $_GET['id'] . '&page=' . $i . '" style="font-size:1.00em;">' . $i . '</a> '; } if ( $end < $totalPages ) echo ' ... '; echo( "<strong> of {$totalPages}</strong>" ); ?> </td> <?php if ($page == $lastPage) { ?> <td width="15%" style="padding:0;"> Next | Last </td> <?php } else { $nextPage = $page + 1; ?> <td width="15%" style="padding:0;"> <a href="?page=<?php echo( $nextPage ); ?>">Next</a> | <a href="?page=<?php echo( $lastPage ); ?>">Last</a> </td> <?php } print "<table align='center' border='1'><tr><td>"; switch ($prod) { default: print "<table align'center'><tr><td align='center'> Please choose what products you'd like to look at:</td></tr>"; echo "<tr><td align='center'> <A HREF=random_product5.php?prod=toys>Toys</A> <A HREF=random_product5.php?prod=batteries>Batteries</A> <A HREF=random_product5.php?prod=auto>Automotive</A> <A HREF=random_product5.php?prod=apparal>Apparal</A> <A HREF=random_product5.php?prod=housewares>Housewares</A> <A HREF=random_product5.php?prod=tools>Tools</A> <A HREF=random_product5.php?prod=hardware>Hardware</A> <A HREF=random_product5.php?prod=electronics>Electronics</A> </td></tr></table>"; } print "</td></tr></table>"; ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 You still don't set $prod before you call it. Add $prod = $_GET['prod']; before the switch. Then if that works, sanitize it. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted February 5, 2008 Share Posted February 5, 2008 If you're just passing it to the page from another page, you'll need to use: $prod = $_GET['prod']; [/prod] Additionally for your links, you need to supply the 'prod' variable to the link, it doesn't just save those variables indefinitely. Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 It is set from another page before you get here with the same switch Quote Link to comment Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Variables don't carry from page to page unless they are global. It is set from another page before you get here with the same switch Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 OK Got the numeric links to work with this: <a href="?prod=' . $_GET['prod'] . '&id=' . $_GET['id'] . '&page=' . $i . '" style="font-size:1.00em;">' . $i . '</a> '; Now I need to fix the text links. Can I use the same procedure? Quote Link to comment Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 Only if its rooted in the same problem. But since you haven't told us what the problem is, we can't really answer that. Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 The problem is I can't get to the next page because the variable $prod was not carrying thru. I got it to work with the numeric links now, but I can't figure out how to get it to work with the text links. This is the numeric link <a href="?prod=' . $_GET['prod'] . '&id=' . $_GET['id'] . '&page=' . $i . '" style="font-size:1.00em;">' . $i . '</a><a href="?prod=' . $_GET['prod'] . '&id=' . $_GET['id'] . '&page=' . $i . '" style="font-size:1.00em;">' . $i . '</a> If someone could explain the text links part that would be great. Here is where I am at: <a href="?'$prod =' . $_GET['prod'] . '&page=1'">First</a> | <a href="?page=<?php echo( $prevPage ); ?>">Previous</a> The problem is I am real new at this pagination thing, couple of days Quote Link to comment 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.