affordit Posted February 4, 2008 Share Posted February 4, 2008 Is there a way to make a hyperlink define a variables value Quote Link to comment Share on other sites More sharing options...
revraz Posted February 4, 2008 Share Posted February 4, 2008 index.php?edit=1 will define $_GET['edit'] as 1 Quote Link to comment Share on other sites More sharing options...
affordit Posted February 4, 2008 Author Share Posted February 4, 2008 I was tring to use this to define the value of $prod to toys <a href="random_product.php?$prod=toys">Toys<a/> The page it is linked to is <?php include("sharons_dbinfo.inc.php"); mysql_connect(mysql,$username,$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'] : 20; $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 } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 4, 2008 Share Posted February 4, 2008 How about doing something like echo "<a href=\"random_product.php?$prod=toys\">Toys<a/>"; Quote Link to comment Share on other sites More sharing options...
affordit Posted February 4, 2008 Author Share Posted February 4, 2008 That did not bring up any of the product from the DB Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 Does the variable $prod carry over to random_product.php in this link echo "<a href=\"random_product.php?$prod=toys\">Toys<a/>"; Quote Link to comment Share on other sites More sharing options...
awpti Posted February 5, 2008 Share Posted February 5, 2008 I'm thinking everyone is missing something simple here. echo '<a href="random_product.php?prod=toys">Toys</a>'; I doubt you're using $prod.. GET vars work like this: www.blah.com/index.php?var=val&var2=val2 PHP sees this as; $_GET['var'] (val) $_GET['var2'] (val2) Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 Thank you I went looking anf this <?php switch ($action) { default: echo "Please choose what products you'd like to look at:<BR>"; echo "<A HREF=random_product5.php?action=toys>Toys</A><BR>"; echo "<A HREF=random_product5.php?action=batteries>Batteries</A>"; } ?> This works very well. I could not figure out how the use the $_get thing but thank you Quote Link to comment Share on other sites More sharing options...
affordit Posted February 5, 2008 Author Share Posted February 5, 2008 Can you tell me why the [/url] shows up with toys on the page the link looks like this Toys[/url] here is the code echo '<a href="random_product.php?action=toys">Toys[/url]'; Quote Link to comment Share on other sites More sharing options...
trq Posted February 5, 2008 Share Posted February 5, 2008 Because its right there in your code. Try... echo '<a href="random_product.php?action=toys">Toys</a>'; 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.